gpt4 book ai didi

javascript - 在 Protractor 中减少权利

转载 作者:行者123 更新时间:2023-11-29 10:08:31 25 4
gpt4 key购买 nike

有两种方法可以减少常规 javascript 数组:

Protractor 中有reduce()这将从左边的元素到最右边的元素起作用:

Apply a reduce function against an accumulator and every element found using the locator (from left-to-right).

Protractor 中是否有reduceRight()方法,如果没有,是否可以基于reduce()实现?

最佳答案

Is there reduceRight() method in Protractor?

不, Protractor 不支持这种方法。

Would it be possible to implement it based on reduce()?

当然,只需将reduce方法中的arr.reduce替换为arr.reduceRight即可:

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);
});
}

关于javascript - 在 Protractor 中减少权利,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38311247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com