Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Currified function that multiples array elements in JavaScript
Problem
We are required to write a JavaScript function that takes in an array and returns another function which in turn takes in a number which returns a new array which is the product of corresponding elements of the input array to the first function and the number provided to the second function.
Example
Following is the code −
const arr = [2, 5, 2, 7, 8, 4];
const num = 4;
const produceWith = (arr = []) => (num) => {
const res = arr.map(el => {
return el * num;
});
return res;
};
console.log(produceWith(arr)(num));
Output
Following is the console output −
[ 8, 20, 8, 28, 32, 16 ]
Advertisements
