There are two ways to reduce regular javascript arrays:
reduce() (from-left-to-right) reduceRight() (from-right-to-left)In Protractor, there is reduce() which would work from the left element to the very right:
Apply a reduce function against an accumulator and every element found using the locator (from left-to-right).
Is there reduceRight() method in Protractor and, if not, would it be possible to implement it based on reduce()?
Is there reduceRight() method in Protractor?
No, protractor doesn't support this method.
Would it be possible to implement it based on reduce()?
Sure, just replace the arr.reduce by arr.reduceRight in the reduce method:
protractor.ElementArrayFinder.prototype.reduceRight = function (reduceFn, initialValue) {
var valuePromise = protractor.promise.fulfilled(initialValue);
return this.asElementFinders_().then(function(arr) {
return arr.reduceRight(function(valuePromise, elementFinder, index) {
return valuePromise.then(function(value) {
return reduceFn(value, elementFinder, index, arr);
});
}, valuePromise);
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With