diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 03eb5f0b20..bdd0defad9 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -63,14 +63,34 @@ // 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 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 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);