Skip to content

Commit 433ae83

Browse files
author
William Coleman
authored
Merge pull request #10 from wcski/array-cardio-1
Array cardio 1
2 parents b4faf6e + 30cc415 commit 433ae83

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

04 - Array Cardio Day 1/index-START.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,34 @@
6363

6464
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
6565
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
66+
/*const category = document.querySelector('.mw-category');
67+
const links = [...category.querySelectorAll('a')];
68+
const de = links
69+
.map(link => link.textContent)
70+
.filter(streetName => streetName.includes('de'));*/
6671

6772

6873
// 7. sort Exercise
6974
// Sort the people alphabetically by last name
75+
const alphabeticalSort = people.sort((a, b) => {
76+
const [aLast, aFirst] = a.split(', ');
77+
const [bLast, bFirst] = b.split(', ');
78+
return aLast > bLast ? 1 : -1;
79+
});
80+
console.log(alphabeticalSort);
7081

7182
// 8. Reduce Exercise
7283
// Sum up the instances of each of these
7384
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
85+
const sum = data.reduce(function(obj, item) {
86+
if(!obj[item]){
87+
obj[item] = 0;
88+
}
89+
obj[item]++;
90+
return obj;
91+
}, {});
92+
93+
console.log(sum);
7494

7595
</script>
7696
</body>

0 commit comments

Comments
 (0)