Visitar URL original
mostly done except #6, can't fetch the list of boulevards from wikipe… · adamwads/JavaScript30@71e3040 · GitHub
Skip to content

Commit 71e3040

Browse files
author
Adam Wadsworth
committed
mostly done except wesbos#6, can't fetch the list of boulevards from wikipedia automatically
1 parent 6f3c4d2 commit 71e3040

1 file changed

Lines changed: 40 additions & 13 deletions

File tree

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

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,30 +66,57 @@
6666
console.log('totalyears: ' + totalyears)
6767

6868
// 5. Sort the inventors by years lived
69-
const inventorsPlusAges = inventors
70-
//console.log(inventors[0])
71-
i = 0
72-
inventors.forEach(function(inventor){
73-
//console.log(inventor)
74-
//console.log(i)
75-
//console.log(ages[i])
76-
//inventorsPlusAges[i].concat(ages[i])
77-
i+=1
69+
console.log('Sort the inventors by years lived: ')
70+
// const inventorsPlusAges = inventors
71+
// //console.log(inventors[0])
72+
// i = 0
73+
// inventors.forEach(function(inventor){
74+
// //console.log(inventor)
75+
// //console.log(i)
76+
// //console.log(ages[i])
77+
// //inventorsPlusAges[i].concat(ages[i])
78+
// i+=1
79+
// })
80+
//console.table(inventorsPlusAges)
81+
82+
const byYearsLived = inventors.sort(function(a,b){
83+
return ((a.year-a.passed) - (b.year-b.passed))
7884
})
79-
console.table(inventorsPlusAges)
85+
console.table(byYearsLived.reverse())
86+
8087

8188
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
8289
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
90+
//a = document.location.load="https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris"
91+
//a = load('https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris')
92+
//console.table(a)
93+
//a = fetch('https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris')
8394

8495

8596
// 7. sort Exercise
8697
// Sort the people alphabetically by last name
98+
alphaName = people.sort(function(a,b){
99+
return((a[0]-b[0]))
100+
})
101+
console.table(alphaName)
87102

88103
// 8. Reduce Exercise
89104
// Sum up the instances of each of these
90-
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
91-
//const ages = inventors.map(inventor => inventor.passed-inventor.year)
92-
//const reducer = (accumulator, currentValue) => accumulator + currentValue
105+
const dataOrig = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
106+
var data = dataOrig.reduce(function(itemCount, currentItem){
107+
if(typeof itemCount[currentItem] !== "undefined"){
108+
itemCount[currentItem]++;
109+
return itemCount;
110+
} else {
111+
itemCount[currentItem]=1;
112+
return itemCount;
113+
}
114+
}, {});
115+
var numItems = [];
116+
for(var x in data){
117+
numItems.push(x + ": " + data[x]);
118+
}
119+
console.log(numItems);
93120

94121
</script>
95122
</body>

0 commit comments

Comments
 (0)