Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/coreUtils.js

Issue 29714613: Issue 6434 - Reimplement positionInParent with indexOf (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Move findIndex up Created March 20, 2018, 11:34 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/content/elemHideEmulation.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/coreUtils.js
===================================================================
--- a/lib/coreUtils.js
+++ b/lib/coreUtils.js
@@ -29,8 +29,29 @@
}
exports.desc = desc;
function extend(cls, properties)
{
return Object.create(cls.prototype, desc(properties));
}
exports.extend = extend;
+
+function findIndex(iterable, callback, thisArg)
+{
+ let index = 0;
+ for (let item of iterable)
+ {
+ if (callback.call(thisArg, item))
+ return index;
+
+ index++;
+ }
+
+ return -1;
+}
+exports.findIndex = findIndex;
+
+function indexOf(iterable, searchElement)
+{
+ return findIndex(iterable, item => item === searchElement);
+}
+exports.indexOf = indexOf;
« no previous file with comments | « lib/content/elemHideEmulation.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld