Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all tests passed #243

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
20 changes: 12 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
function find(array, callback) {
for (let element of array) {
// Write your code here.
if (callback(element)) return element
}
return undefined
}
}

/**
* Returns an array of all elements in the array that cause the callback to return `true`. If the array is empty or no elements cause the callback to return `true`, then return an empty array.
Expand All @@ -32,14 +34,15 @@ function find(array, callback) {
* filter([1, 2, 3], (element) => element < 0);
* //> []
*/
function filter(array, callback) {
function filter(array, callback){
const result = [];
for (let element of array) {
for (let element of array)
// Write your code here.
}
return result;
if (callback(element)) {
result.push(element)
}
return result
}

/**
* Returns an array where each element is transformed by the callback. If the array is empty, return an empty array.
* @param {*[]} array - An array of elements. Could be anything!
Expand All @@ -58,10 +61,10 @@ function map(array, callback) {
const result = [];
for (let element of array) {
// Write your code here.
result.push(callback(element))
}
return result;
return result
}

/**
* Does not return anything. Passes each element of the array into the callback along with the index and the array, in that order.
* @param {*[]} array - An array of elements. Could be anything!
Expand All @@ -78,6 +81,7 @@ function map(array, callback) {
function forEach(array, callback) {
for (let i = 0; i < array.length; i++) {
// Write your code here.
callback(array[i], i, array)
}
}

Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.