Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 49 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand All @@ -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())
}

/**
Expand All @@ -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)
}

/**
Expand All @@ -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)
}

/**
Expand All @@ -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) {

}

/////////////// HIGHER-ORDER ARRAY METHODS ///////////////
Expand All @@ -155,8 +155,13 @@ 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 lower = [];
strings.forEach((item) => {
lower.push(item.toLowerCase())

});
return lower
}

/**
Expand All @@ -174,8 +179,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) {
return (strings.map((item) => {
if(item === 'apple'){
return true;} else {
return false;
}
}));
}

/**
Expand All @@ -194,8 +204,10 @@ function isItAnApple(/* code here */) {
*
* [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')
});
}

/**
Expand All @@ -213,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
Expand All @@ -232,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;
}

/**
Expand All @@ -248,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;
}

/**
Expand All @@ -266,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)

});


}

/**
Expand Down