From 160df3af0e600008de86cb700f7956c3136176a0 Mon Sep 17 00:00:00 2001 From: Mustafa Hassan <60632959+MustafaCajib@users.noreply.github.com> Date: Sun, 15 Mar 2020 18:55:01 -0700 Subject: [PATCH 1/3] 5 passing --- index.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index f61169392..8872496c5 100644 --- a/index.js +++ b/index.js @@ -48,8 +48,8 @@ function processFirstItem(stringList, callback) { * [2] Invoking `processLength` passing `[]` and `(num) => "There are " + num`, * should return "There are 0". */ -function processLength(/* CODE HERE */) { - /* CODE HERE */ +function processLength(list , callback) { +return callback(list.length) } /** @@ -66,8 +66,8 @@ function processLength(/* CODE HERE */) { * Invoking `processLastItem` passing `['foo', 'bar']` and `(str) => str + str`, * should return 'barbar'. */ -function processLastItem(/* CODE HERE */) { - /* CODE HERE */ +function processLastItem(stringList, callback) { + return callback(stringList.pop()) } /** @@ -88,8 +88,8 @@ function processLastItem(/* CODE HERE */) { * [2] Invoking `processSum` passing `-5`, '-1', and `(num) => num + 1000`, * should return 994. */ -function processSum(/* CODE HERE */) { - /* CODE HERE */ +function processSum(num1, num2, callback) { + return callback(num1 + num2) } /** @@ -110,8 +110,8 @@ function processSum(/* CODE HERE */) { * [2] Invoking `processProduct` passing 25 and 0 and `(num) => num + 1000`, * should return 1000. */ -function processProduct(/* CODE HERE */) { - /* CODE HERE */ +function processProduct(num1, num2, callback) { + return callback(num1 * num2) } /** @@ -132,8 +132,8 @@ function processProduct(/* CODE HERE */) { * [2] Invoking `processDuplicateFree` passing `[1,1,2,2,3]` and `(arr) => arr.length`, * should return 3. */ -function processDuplicateFree(/* CODE HERE ONLY AFTER COMPLETING ALL OTHER TASKS */) { - /* CODE HERE ONLY AFTER COMPLETING ALL OTHER TASKS */ +function processDuplicateFree(list , callback) { + } /////////////// HIGHER-ORDER ARRAY METHODS /////////////// From f4c9bb325466de938a75c5d4cc99525fc55b1da9 Mon Sep 17 00:00:00 2001 From: Mustafa Hassan <60632959+MustafaCajib@users.noreply.github.com> Date: Mon, 16 Mar 2020 02:02:35 -0700 Subject: [PATCH 2/3] filter --- index.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 8872496c5..6c99a98da 100644 --- a/index.js +++ b/index.js @@ -132,8 +132,8 @@ function processProduct(num1, num2, callback) { * [2] Invoking `processDuplicateFree` passing `[1,1,2,2,3]` and `(arr) => arr.length`, * should return 3. */ -function processDuplicateFree(list , callback) { - +function processDuplicateFree(list) { + } /////////////// HIGHER-ORDER ARRAY METHODS /////////////// @@ -155,8 +155,10 @@ function processDuplicateFree(list , callback) { * * [2] Invoking `lowerCaseStrings` with `['a', 'b', 'c' ]` will return `[ 'a', 'b', 'c' ]`. */ -function lowerCaseStrings(/* code here */) { - /* code here */ +function lowerCaseStrings(strings) { +strings.forEach((item) =>{ + console.log(strings.toLowerCase) ; +}); } /** @@ -174,8 +176,13 @@ function lowerCaseStrings(/* code here */) { * * [2] Invoking `isItAnApple` with `['a', 'b', 'c' ]` will return `[ false, false, false ]`. */ -function isItAnApple(/* code here */) { - /* code here */ +function isItAnApple(strings) { + strings.map(() => { + if(strings === 'apple'){ + return true;} else { + return false; + } + }); } /** From ba0045288be212596059ebbc9d5fb7cb981b9c2f Mon Sep 17 00:00:00 2001 From: Mustafa Hassan <60632959+MustafaCajib@users.noreply.github.com> Date: Tue, 17 Mar 2020 18:02:42 -0700 Subject: [PATCH 3/3] done --- index.js | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 6c99a98da..e72b25eb1 100644 --- a/index.js +++ b/index.js @@ -156,9 +156,12 @@ function processDuplicateFree(list) { * [2] Invoking `lowerCaseStrings` with `['a', 'b', 'c' ]` will return `[ 'a', 'b', 'c' ]`. */ function lowerCaseStrings(strings) { -strings.forEach((item) =>{ - console.log(strings.toLowerCase) ; + const lower = []; + strings.forEach((item) => { + lower.push(item.toLowerCase()) + }); +return lower } /** @@ -177,12 +180,12 @@ strings.forEach((item) =>{ * [2] Invoking `isItAnApple` with `['a', 'b', 'c' ]` will return `[ false, false, false ]`. */ function isItAnApple(strings) { - strings.map(() => { - if(strings === 'apple'){ + return (strings.map((item) => { + if(item === 'apple'){ return true;} else { return false; } - }); + })); } /** @@ -201,8 +204,10 @@ function isItAnApple(strings) { * * [2] Invoking `removeApple` with `['a', 'b', 'c' ]` will return `[ 'a', 'b', 'c' ]`. */ -function removeApple(/* code here */) { - /* code here */ +function removeApple(string) { + return string.filter((fruits) => { +return (fruits !== 'apple') + }); } /** @@ -220,8 +225,10 @@ function removeApple(/* code here */) { * * [2] Invoking `stringSmash` with `['a', 'b', 'c' ]` will return `abc`. */ -function stringSmash(/* code here */) { - /* code here */ +function stringSmash(strings) { + return strings.reduce((accm, touch) => { + return accm + touch; +}); } // A local community center is holding a fund raising 5k fun run and has invited @@ -239,8 +246,11 @@ function stringSmash(/* code here */) { * @returns an array with all the runners' full names in the following format: "Smith, John". * The full names appear in the array in the same order the runners appear in the `runners` array. */ -function getFullNames(/* CODE HERE */) { - /* CODE HERE */ +function getFullNames(runners) { + const full = runners.map((item) =>{ + return `${item.last_name}, ${item.first_name}` + }); + return full; } /** @@ -255,8 +265,11 @@ function getFullNames(/* CODE HERE */) { * @returns an array with all the runners' first names in ALL CAPS. * The first names appear in the array in the same order the runners appear in the `runners` array. */ -function firstNamesAllCaps(/* CODE HERE */) { - /* CODE HERE */ +function firstNamesAllCaps(runners) { + const caps = runners.map((item) =>{ + return item.first_name.toUpperCase(); + }); + return caps; } /** @@ -273,8 +286,13 @@ function firstNamesAllCaps(/* CODE HERE */) { * @returns an array containing only the runners that use the given `tShirtSize`. * The runners in the array appear in the same order they appear in the `runners` array. */ -function getRunnersByTShirtSize(/* CODE HERE */) { - /* CODE HERE */ +function getRunnersByTShirtSize(runners , tShirtSize) { + return runners.filter((item) =>{ + return (runners + tShirtSize) + + }); + + } /**