Skip to content

Commit 3ed6bd3

Browse files
author
laryl.li
committed
Solved wesbos#8 Reduce Exercise. I need more practice with reduce function
1 parent 96be817 commit 3ed6bd3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@
9999
// Sum up the instances of each of these
100100
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
101101

102+
const dataobjectarray=[]
103+
for(let i = 0; i<data.length; i++) {
104+
for (let j = 0; j < dataobjectarray.length; j++) {
105+
if (dataobjectarray[j].type == data[i]) {
106+
dataobjectarray[j].amount += 1;
107+
}
108+
}
109+
if(!(dataobjectarray.some(vehicle => vehicle.type == data[i]))) {
110+
let newvehicle = new Object();
111+
newvehicle.type = data[i];
112+
newvehicle.amount = 1;
113+
dataobjectarray.push(newvehicle);
114+
}
115+
}
116+
console.log(dataobjectarray);
117+
118+
119+
102120
</script>
103121
</body>
104122
</html>

0 commit comments

Comments
 (0)