

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 ]
- Related Questions & Answers
- Array of multiples - JavaScript
- Constructing multiples array - JavaScript
- Sort elements of the array that occurs in between multiples of K in C++
- Elements that appear twice in array in JavaScript
- Find array elements that are out of order in JavaScript
- Frequency of elements of one array that appear in another array using JavaScript
- Sum of all multiples in JavaScript
- Finding sum of multiples in JavaScript
- JavaScript function that should count all unique items in an array
- JavaScript array: Find all elements that appear more than n times
- Sorting Array Elements in Javascript
- Rearranging array elements in JavaScript
- Constructing an array of first n multiples of an input number in JavaScript
- Array elements that appear more than once?
- C++ program to rearrange all elements of array which are multiples of x in increasing order
Advertisements