From 6cb6a23694063001b731b248590a226f96746316 Mon Sep 17 00:00:00 2001 From: "RELIAS\\wcoleman" Date: Wed, 11 Oct 2017 18:00:24 -0400 Subject: [PATCH 1/3] gets an aray of dom elements containing specific text --- 04 - Array Cardio Day 1/index-START.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 03eb5f0b20..a497e5d615 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -63,6 +63,8 @@ // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris + const category = document.querySelector('.mw-category'); + const links = category.querySelectorAll('a'); // 7. sort Exercise From 58b2cd714d34c155a6a132f7a10fc02969213312 Mon Sep 17 00:00:00 2001 From: "RELIAS\\wcoleman" Date: Wed, 11 Oct 2017 18:17:15 -0400 Subject: [PATCH 2/3] added sort with split --- 04 - Array Cardio Day 1/index-START.html | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index a497e5d615..045f191289 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -63,12 +63,21 @@ // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris - const category = document.querySelector('.mw-category'); - const links = category.querySelectorAll('a'); + /* const category = document.querySelector('.mw-category'); + const links = [...category.querySelectorAll('a')]; + const de = links + .map(link => link.textContent) + .filter(streetName => streetName.includes('de'));*/ // 7. sort Exercise // Sort the people alphabetically by last name + const alphabeticalSort = people.sort((a, b) => { + const [aLast, aFirst] = a.split(', '); + const [bLast, bFirst] = b.split(', '); + return aLast > bLast ? 1 : -1; + }); + console.log(alphabeticalSort); // 8. Reduce Exercise // Sum up the instances of each of these From 30cc415e249a23a2522d4b193e408bb0359a407e Mon Sep 17 00:00:00 2001 From: "RELIAS\\wcoleman" Date: Wed, 11 Oct 2017 18:29:04 -0400 Subject: [PATCH 3/3] added reduce function --- 04 - Array Cardio Day 1/index-START.html | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 045f191289..bdd0defad9 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -63,7 +63,7 @@ // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris - /* const category = document.querySelector('.mw-category'); + /*const category = document.querySelector('.mw-category'); const links = [...category.querySelectorAll('a')]; const de = links .map(link => link.textContent) @@ -82,6 +82,15 @@ // 8. Reduce Exercise // Sum up the instances of each of these const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ]; + const sum = data.reduce(function(obj, item) { + if(!obj[item]){ + obj[item] = 0; + } + obj[item]++; + return obj; + }, {}); + + console.log(sum);