JavaScript: Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function
JavaScript fundamental (ES6 Syntax) exercises, practice and solution: Exercise-138 with Solution
Write a JavaScript program that takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function.
Note: Use closures and the spread operator (...) to map the array of arguments to the inputs of the function.
- Use a closure and the spread operator (...) to map the array of arguments to the inputs of the function.
Sample Solution:
JavaScript Code:
//#Source https://bit.ly/2neWfJ2
const spreadOver = fn => argsArr => fn(...argsArr);
const arrayMax = spreadOver(Math.max);
console.log(arrayMax([1, 2, 3]));
Sample Output:
3
Pictorial Presentation:
Flowchart:

Live Demo:
See the Pen javascript-basic-exercise-138-1 by w3resource (@w3resource) on CodePen.
Improve this sample solution and post your code through Disqus
Previous: Write a JavaScript program to perform stable sorting of an array, preserving the initial indexes of items when their values are the same. Do not mutate the original array, but returns a new array instead.
Next: Write a JavaScript program to split a multiline string into an array of lines.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join