From de109ebc64ea67e3cfe4083841c1ba1dbfc39cd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98Brittany?= Date: Mon, 8 Oct 2018 21:06:49 -0400 Subject: [PATCH 1/2] finished challenge 1 and 2 --- .../challenges/challenges-01.test.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/01-smacss-media-queries/challenges/challenges-01.test.js b/01-smacss-media-queries/challenges/challenges-01.test.js index f9ca403..020181d 100644 --- a/01-smacss-media-queries/challenges/challenges-01.test.js +++ b/01-smacss-media-queries/challenges/challenges-01.test.js @@ -9,11 +9,11 @@ Then, write a function named speaker that takes in a string and a callback funct ------------------------------------------------------------------------------------------------ */ const greeting = (word) => { - // Solution code here... + return word.toUpperCase(); } const speaker = (message, callback) => { - // Solution code here... + return callback(message); } /* ------------------------------------------------------------------------------------------------ @@ -33,11 +33,14 @@ Return the modified array. ------------------------------------------------------------------------------------------------ */ const addValues = (arr, value) => { - // Solution code here... + arr.push(value); } const addNumbers = (num, arr, times, callback) => { - // Solution code here... + for(let i = 0; i < times; i++){ + arr.push(num); + } + return arr; } /* ------------------------------------------------------------------------------------------------ @@ -53,11 +56,15 @@ Return the modified array. ------------------------------------------------------------------------------------------------ */ const removeOne = (num, arr) => { - // Solution code here... + if(num % 3 === 2){ + arr.pop; + } } const removeElements = (arr, callback) => { - // Solution code here... + for (let i = 0; i < arr.length; i++){ + callback(arr[i], arr); + } } /* ------------------------------------------------------------------------------------------------ From d7cf7a9f3876ea0b176ad1bd9493b4e829049b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98Brittany?= Date: Tue, 9 Oct 2018 19:17:19 -0400 Subject: [PATCH 2/2] finished challenges --- .../challenges/challenges-01.test.js | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/01-smacss-media-queries/challenges/challenges-01.test.js b/01-smacss-media-queries/challenges/challenges-01.test.js index 020181d..bdc16f6 100644 --- a/01-smacss-media-queries/challenges/challenges-01.test.js +++ b/01-smacss-media-queries/challenges/challenges-01.test.js @@ -57,7 +57,7 @@ Return the modified array. const removeOne = (num, arr) => { if(num % 3 === 2){ - arr.pop; + arr.pop(); } } @@ -65,6 +65,7 @@ const removeElements = (arr, callback) => { for (let i = 0; i < arr.length; i++){ callback(arr[i], arr); } + return arr; } /* ------------------------------------------------------------------------------------------------ @@ -74,7 +75,10 @@ Write a function named removeWithForEach that produces the same output as challe ------------------------------------------------------------------------------------------------ */ const removeWithForEach = (arr, callback) => { - // Solution code here... + arr.forEach((val) => { + callback(val, arr) + }) + return arr; } /* ------------------------------------------------------------------------------------------------ @@ -88,7 +92,12 @@ This anonymous function should accept up to three arguments: the element, the in ------------------------------------------------------------------------------------------------ */ const removeWithAnon = (arr) => { - // Solution code here... + arr.forEach((val, index, arr) => { + if(val % 3 === 2){ + arr.pop(); + } + }) + return arr; } /* ------------------------------------------------------------------------------------------------ @@ -109,7 +118,13 @@ This function should use forEach to populate your grocery list based on the stor ------------------------------------------------------------------------------------------------ */ const createList = (availableItems) => { - // Solution code here... + let groceryList = []; + availableItems.forEach((val) => { + if (val.available === true) { + groceryList.push(val.name); + } + }) + return groceryList; } /* ------------------------------------------------------------------------------------------------ @@ -127,7 +142,22 @@ Return the resulting output array. ------------------------------------------------------------------------------------------------ */ const fizzbuzz = (arr) => { - // Solution code here... + let output = []; + arr.forEach((val) => { + if ((val % 3 === 0) && (val % 5 === 0)) { + output.push("Fizz Buzz") + } + else if (val % 3 === 0){ + output.push("Fizz"); + } + else if (val % 5 === 0){ + output.push("Buzz"); + } + else { + output.push(val); + } + }) + return output; } /* ------------------------------------------------------------------------------------------------