Skip to content
Prev Previous commit
Next Next commit
Solved wesbos#8 Reduce Exercise. I need more practice with reduce fun…
…ction
  • Loading branch information
laryl.li committed Feb 9, 2020
commit 3ed6bd398a3708218b71ce2e3dac08513c7a29c6
18 changes: 18 additions & 0 deletions 04 - Array Cardio Day 1/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@
// 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 dataobjectarray=[]
for(let i = 0; i<data.length; i++) {
for (let j = 0; j < dataobjectarray.length; j++) {
if (dataobjectarray[j].type == data[i]) {
dataobjectarray[j].amount += 1;
}
}
if(!(dataobjectarray.some(vehicle => vehicle.type == data[i]))) {
let newvehicle = new Object();
newvehicle.type = data[i];
newvehicle.amount = 1;
dataobjectarray.push(newvehicle);
}
}
console.log(dataobjectarray);



</script>
</body>
</html>