reduceRight function
dynamic
reduceRight(])
Implementation
dynamic reduceRight(List list,
dynamic Function(dynamic prev, dynamic curr, int index, List list) fn,
[initialValue]) {
var length = list.length;
var index = length - 1;
var value;
var isValueSet = false;
if (1 < list.length) {
value = initialValue;
isValueSet = true;
}
for (; -1 < index; --index) {
if (isValueSet) {
value = fn(value, list[index], index, list);
} else {
value = list[index];
isValueSet = true;
}
}
if (!isValueSet) {
throw TypeError(); //'Reduce of empty array with no initial value'
}
return value;
}