javascript
function multiplyByTwo(number) {
return number * 2;
}
function applyFunctionToArray(array, func) {
let result = [];
for (let i = 0; i < array.length; i++) {
result.push(func(array[i]));
}
return result;
}
let numbers = [1, 2, 3, 4, 5];
let doubledNumbers = applyFunctionToArray(numbers, multiplyByTwo);
console.log(doubledNumbers);
javascript
function createMultiplier(multiplier) {
return function(number) {
return number * multiplier;
}
}
let double = createMultiplier(2);
let triple = createMultiplier(3);
console.log(double(5)); // 10
console.log(triple(5)); // 15
javascript
let numbers = [1, 2, 3, 4, 5];
let evenNumbers = numbers.filter(function(number) {
return number % 2 === 0;
});
console.log(evenNumbers);
javascript
function applyFunctionToArray(array, func) {
let result = [];
for (let i = 0; i < array.length; i++) {
result.push(func(array[i]));
}
return result;
}
let numbers = [1, 2, 3, 4, 5];
let doubledNumbers = applyFunctionToArray(numbers, function(number) {
return number * 2;
});
console.log(doubledNumbers);
javascript
let add = function(a, b) {
return a + b;
};
let result = add(2, 3);
console.log(result); // 5