Skip to content

Instantly share code, notes, and snippets.

@Shadid12
Created Dec 6, 2021
Embed
What would you like to do?
const doubleEachElement = (arr) => {
return arr.map(element => element == 1 ? 2 : element * 2);
}
const squareEachElement = (arr) => {
return arr.map(element => element * element);
}
const printOriginalAndModify = (arr, fn) => {
console.log('☎️ original', arr);
const modified = fn(arr);
console.log('📱 modified', modified);
return modified;
}
const divideByTwo = (arr) => {
return arr.map(element => element / 2);
}
printOriginalAndModify([1, 2, 3, 4, 5], divideByTwo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment