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
41 changes: 22 additions & 19 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[stringList.length - 1]);
}

/**
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,9 @@ 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) {
let DupeFreeSet = new Set(list);
return callback(Array.from(DupeFreeSet));
}

/////////////// HIGHER-ORDER ARRAY METHODS ///////////////
Expand All @@ -155,8 +156,10 @@ 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) {
let LCstrings = [];
strings.forEach(strings => { LCstrings.push(strings.toLowerCase()) });
return LCstrings;
}

/**
Expand All @@ -174,8 +177,8 @@ 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(strings => (strings === 'apple') ? true : false);
}

/**
Expand All @@ -194,8 +197,8 @@ function isItAnApple(/* code here */) {
*
* [2] Invoking `removeApple` with `['a', 'b', 'c' ]` will return `[ 'a', 'b', 'c' ]`.
*/
function removeApple(/* code here */) {
/* code here */
function removeApple(strings) {
return strings.filter(strings => strings != 'apple');
}

/**
Expand All @@ -213,8 +216,8 @@ 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((first, last) => first += last);
}

// A local community center is holding a fund raising 5k fun run and has invited
Expand Down Expand Up @@ -358,7 +361,7 @@ if (typeof exports !== 'undefined') {
if (processSum) { module.exports.processSum = processSum }
if (processProduct) { module.exports.processProduct = processProduct }
if (processDuplicateFree) { module.exports.processDuplicateFree = processDuplicateFree }
if (lowerCaseStrings ) { module.exports.lowerCaseStrings = lowerCaseStrings}
if (lowerCaseStrings) { module.exports.lowerCaseStrings = lowerCaseStrings }
if (isItAnApple) { module.exports.isItAnApple = isItAnApple }
if (removeApple) { module.exports.removeApple = removeApple }
if (stringSmash) { module.exports.stringSmash = stringSmash }
Expand Down