diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index eec0ffc31d..c78d3b6cb3 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -31,29 +31,49 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's +inventors.filter(el => { el.year >= 1500 && el.year < 1600 }) // Array.prototype.map() // 2. Give us an array of the inventors' first and last names +inventors.map(i => `${i.first} ${i.last}`) // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest +inventors.sort((a, b) => a.year - b.year) // Array.prototype.reduce() // 4. How many years did all the inventors live? +//861 +inventors.reduce((total, i) => { + let yearsLived = i.passed - i.year; + return total + yearsLived; +}, 0); // 5. Sort the inventors by years lived +inventors.sort((a, b) => { + return (a.passed - a.year) > (b.passed - b.year) ? 1 : -1 +}) // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris +Array.from(document.querySelectorAll('li a')).map(el => el.title).filter(title => /de/.test(title)) // 7. sort Exercise // Sort the people alphabetically by last name +people.sort() // 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' ]; +data.reduce((total, el) => { + if (!total[el]) total[el] = 0; + + total[el] += 1 + return total +}, {}) +