Skip to content Skip to sidebar Skip to footer

How I Can Solve Aperture Function In Javascript?

I want solve a function called aperture which accept a number and an array that should return new array that should be composed of subarrays the size of the number with consecutive

Solution 1:

Create an empty array whose length is equal to the given number and use reduce() on it.

const aperture = (num,arr) => [...Array(num)].reduce((ac,_,i) => {
  ac.push(arr.slice(i,num+i));
  return ac;
},[])

console.log(aperture(3,[1,2,3,4,5]))

Post a Comment for "How I Can Solve Aperture Function In Javascript?"