reduceRight
Map the values in this list to a single value from right to left
list.reduceRight(callback, initialValue, [, thisArg])
Loops through the values of the list in reverse order, calling callback
for each one until the list
ends. The return value of callback
is passed to the next iteration as the first argument,
and finally returned by reduce
.
var todos = new DefineList([
{name: "dishes", complete: false},
{name: "lawn", complete: true}
]);
var todosAsOneObject = todos.reduce(function(todos, todo){
todos[todo.name] = todo.complete;
return todos;
}, {});
todosAsOneObject //-> { dishes: false, lawn: true }
Parameters
- callback
{function(item, index, list)}
:A function to call with each element of the DefineList. The four parameters that callback gets passed are:
- current (*) - the current aggregate value of reducing over the list -- the initial value if the first iteration
- item (*) - the element at index.
- index (Integer) - the index of the current element of the list.
- list (DefineList) - the
DefineList
the elements are coming from.
The return value of
callback
is passed to the next iteration as the first argument, and returned fromreduce
if the last iteration. - initialValue
{*}
:The initial value to use as
current
in the first iteration - thisArg
{Object}
:The object to use as
this
inside the callback.
Returns
{*}
:
The result of the final call of callback
on the list.