- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- Constructing multiples array - JavaScript
- Array of multiples - 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
- JavaScript function that should count all unique items in an array
- Rearranging array elements in JavaScript
- Constructing an array of first n multiples of an input number in JavaScript
- JavaScript array: Find all elements that appear more than n times
- Array findIndex() function in JavaScript
- Array some() function in JavaScript
- Sum of all multiples in JavaScript
- Finding sum of multiples in JavaScript
- Consecutive elements sum array in JavaScript

Advertisements