Reputation: 15541
I am trying to get into functional programming and after creating a number of pure functions, I have two arrays where I need to create a new array which is the first array with one of its properties updated from the second array.
I have a commands array and a seconds integer array.
The commands array has objects like this :
var SerialCommand = function(serialString, waitTime) {
this.serialString = serialString;
this.waitTime = waitTime;
}
Seconds is simply an integer array with the same number of elements as the commands array.
What I want is finally an array where each element of commands array has the following update to it:
command.waitTime = numSeconds;
I have created the following function:
var updateSeconds = function(command, numSeconds) {
command.waitTime = numSeconds;
return command;
}
but not sure how to combine it with the arrays.
I am using Ramda for my library but any help with any other library will do.
Upvotes: 2
Views: 586
Reputation: 148
R.zipWith() seems to be the right thing for you. http://ramdajs.com/0.18.0/docs/#zipWith
Upvotes: 4