0

I am learning functional programming, looking into my code I was just wondering is it possible to do the same thing but using map / reduce function?

Given that I have two values:

var firstDate = 1964
var lastDate = 2018

I want to get the years in between including itself. I could simply do:

var years = [] 

for(var i=firstDate;i<=lastDate;i++)
    years.push(i)

return years

Is it possible to do the same thing in a declarative way? So, I would first create an array with the desired size

const years = new Array(lastDate - firstDate)

then how can I map the index to each element?

years.map((val, i, arr) => ???)
Anson C
  • 437
  • 3
  • 15

0 Answers0