diff --git a/.vscode/settings.json b/.vscode/settings.json index 95b2d6470..bd2c1a2f5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "standard.enable": false + "standard.enable": false, + "liveServer.settings.port": 5501 } \ No newline at end of file diff --git a/index.js b/index.js index f61169392..25da0eb98 100644 --- a/index.js +++ b/index.js @@ -48,8 +48,9 @@ function processFirstItem(stringList, callback) { * [2] Invoking `processLength` passing `[]` and `(num) => "There are " + num`, * should return "There are 0". */ -function processLength(/* CODE HERE */) { +function processLength(list, callback) { /* CODE HERE */ + return callback(list.length) } /** @@ -66,8 +67,9 @@ function processLength(/* CODE HERE */) { * Invoking `processLastItem` passing `['foo', 'bar']` and `(str) => str + str`, * should return 'barbar'. */ -function processLastItem(/* CODE HERE */) { +function processLastItem(stringList, callback) { /* CODE HERE */ + return callback(stringList[stringList.length - 1]) } /** @@ -88,10 +90,12 @@ function processLastItem(/* CODE HERE */) { * [2] Invoking `processSum` passing `-5`, '-1', and `(num) => num + 1000`, * should return 994. */ -function processSum(/* CODE HERE */) { +function processSum(num1, num2, callback) { /* CODE HERE */ + return callback(num1 + num2) } + /** * ### Challenge `processProduct` * @@ -110,10 +114,10 @@ function processSum(/* CODE HERE */) { * [2] Invoking `processProduct` passing 25 and 0 and `(num) => num + 1000`, * should return 1000. */ -function processProduct(/* CODE HERE */) { +function processProduct(num1, num2, callback) { /* CODE HERE */ + return callback(num1 * num2) } - /** * ### Challenge `processDuplicateFree` * THIS IS A STRETCH PROBLEM! ATTEMPT ONLY AFTER COMPLETING ALL NON-STRETCH CHALLENGES! @@ -155,10 +159,16 @@ function processDuplicateFree(/* CODE HERE ONLY AFTER COMPLETING ALL OTHER TASKS * * [2] Invoking `lowerCaseStrings` with `['a', 'b', 'c' ]` will return `[ 'a', 'b', 'c' ]`. */ -function lowerCaseStrings(/* code here */) { - /* code here */ +function lowerCaseStrings(strings) { + const stringArray = []; + const lowerCaseArray = strings.forEach(function(string){ + stringArray.push(string.toLowerCase()) + + }) + return stringArray; } + /** * ### Challenge `isItAnApple` * @@ -174,8 +184,17 @@ function lowerCaseStrings(/* code here */) { * * [2] Invoking `isItAnApple` with `['a', 'b', 'c' ]` will return `[ false, false, false ]`. */ -function isItAnApple(/* code here */) { +function isItAnApple(strings) { /* code here */ + const newArray = []; + strings.map(function(string) { + if (string === "apple"){ + newArray.push(true); + } else { + newArray.push(false); + } + }) + return newArray } /** @@ -194,8 +213,12 @@ function isItAnApple(/* code here */) { * * [2] Invoking `removeApple` with `['a', 'b', 'c' ]` will return `[ 'a', 'b', 'c' ]`. */ -function removeApple(/* code here */) { +function removeApple(strings) { /* code here */ + const rmvApple = strings.filter(function(fruit){ + return fruit !== "apple" + }) + return rmvApple } /** @@ -213,8 +236,12 @@ function removeApple(/* code here */) { * * [2] Invoking `stringSmash` with `['a', 'b', 'c' ]` will return `abc`. */ -function stringSmash(/* code here */) { +function stringSmash(strings) { /* code here */ + const newString = strings.reduce(function(accumulator, string){ + return accumulator + string; + }, ""); + return newString } // A local community center is holding a fund raising 5k fun run and has invited @@ -232,8 +259,13 @@ 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 */) { +function getFullNames(runners) { /* CODE HERE */ + const runnerNames = []; + runners.forEach(function(runners){ + return runnerNames.push(`${runners.last_name}, ${runners.first_name}`) + }) + return runnerNames } /** @@ -248,8 +280,12 @@ 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 */) { +function firstNamesAllCaps(runners) { /* CODE HERE */ + const drunkWithPower = runners.map(function(runners){ + return runners.first_name.toUpperCase(); + }) + return drunkWithPower } /** @@ -266,8 +302,12 @@ 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 */) { +function getRunnersByTShirtSize(runners, tShirtSize) { /* CODE HERE */ + const crazyEventDirector = runners.filter(function(runner){ + return runner.shirt_size === tShirtSize + }) + return crazyEventDirector } /** diff --git a/package-lock.json b/package-lock.json index 62655cc18..06c4011e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,9 +35,9 @@ } }, "acorn": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz", - "integrity": "sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz", + "integrity": "sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==", "dev": true }, "acorn-jsx": { @@ -2815,9 +2815,9 @@ } }, "kind-of": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", - "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", + "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", "dev": true }, "lcid": {