MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / filter

Function filter

javascript/selenium-webdriver/lib/promise.js:166–183  ·  view source on GitHub ↗

* Calls a function for each element in an array, and if the function returns * true adds the element to a new array. * * If the return value of the filter function is a promise, this function * will wait for it to be fulfilled before determining whether to insert the * element into the new arra

(array, fn, self = undefined)

Source from the content-addressed store, hash-verified

164 * @template TYPE, SELF
165 */
166async function filter(array, fn, self = undefined) {
167 const v = await Promise.resolve(array)
168 if (!Array.isArray(v)) {
169 throw TypeError('not an array')
170 }
171
172 const arr = /** @type {!Array} */ (v)
173 const values = []
174
175 for (const [index, item] of arr.entries()) {
176 const isConditionTrue = await Promise.resolve(fn.call(self, item, index, arr))
177 if (isConditionTrue) {
178 values.push(item)
179 }
180 }
181
182 return values
183}
184
185/**
186 * Returns a promise that will be resolved with the input value in a

Callers 6

collect_files_from_cacheFunction · 0.85
get_chrome_milestoneFunction · 0.85
get_device_withMethod · 0.85

Calls 3

entriesMethod · 0.80
callMethod · 0.65
resolveMethod · 0.45

Tested by

no test coverage detected