From 3ea4074e52703243979c0a5bba29ae9c5326ab90 Mon Sep 17 00:00:00 2001 From: Cornelius Asogwa Date: Thu, 31 Oct 2024 08:24:30 +0100 Subject: [PATCH 1/2] Complete exercises except data exercise --- 04 - Array Cardio Day 1/index-START.html | 188 ++++++++++++++++------- 1 file changed, 135 insertions(+), 53 deletions(-) diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 0dcfd00f40..13734b3ef5 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -1,66 +1,148 @@ - - - Array Cardio 💪 - - - -

Psst: have a look at the JavaScript Console 💁

- - + // 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', + ]; + + From 8a3381c84670c398cec265e36a5c4c607ef0c10d Mon Sep 17 00:00:00 2001 From: Cornelius Asogwa Date: Thu, 31 Oct 2024 14:37:47 +0100 Subject: [PATCH 2/2] Complete data exercise --- 04 - Array Cardio Day 1/index-START.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 13734b3ef5..572f5895a0 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -143,6 +143,13 @@ 'car', 'truck', ]; + const transportByNum = data.reduce((key, value) => { + if (!key[value]) { + key[value] = 0; + } + key[value]++; + return key; + }, {});