summaryrefslogtreecommitdiff
path: root/services/sync/tps/extensions/mozmill/resource/stdlib/arrays.js
diff options
context:
space:
mode:
authorPale Moon <git-repo@palemoon.org>2016-09-01 13:39:08 +0200
committerPale Moon <git-repo@palemoon.org>2016-09-01 13:39:08 +0200
commit3d8ce1a11a7347cc94a937719c4bc8df46fb8d14 (patch)
tree8c26ca375a6312751c00a27e1653fb6f189f0463 /services/sync/tps/extensions/mozmill/resource/stdlib/arrays.js
parente449bdb1ec3a82f204bffdd9c3c54069d086eee3 (diff)
downloadpalemoon-gre-3d8ce1a11a7347cc94a937719c4bc8df46fb8d14.tar.gz
Base import of Tycho code (warning: huge commit)
Diffstat (limited to 'services/sync/tps/extensions/mozmill/resource/stdlib/arrays.js')
-rw-r--r--services/sync/tps/extensions/mozmill/resource/stdlib/arrays.js44
1 files changed, 31 insertions, 13 deletions
diff --git a/services/sync/tps/extensions/mozmill/resource/stdlib/arrays.js b/services/sync/tps/extensions/mozmill/resource/stdlib/arrays.js
index f33beda38..c70a262c9 100644
--- a/services/sync/tps/extensions/mozmill/resource/stdlib/arrays.js
+++ b/services/sync/tps/extensions/mozmill/resource/stdlib/arrays.js
@@ -1,49 +1,65 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+ * file, you can obtain one at http://mozilla.org/MPL/2.0/. */
-var EXPORTED_SYMBOLS = ['inArray', 'getSet', 'indexOf', 'rindexOf', 'compare'];
+var EXPORTED_SYMBOLS = ['inArray', 'getSet', 'indexOf',
+ 'remove', 'rindexOf', 'compare'];
-function inArray (array, value) {
- for (i in array) {
+
+function remove(array, from, to) {
+ var rest = array.slice((to || from) + 1 || array.length);
+ array.length = from < 0 ? array.length + from : from;
+
+ return array.push.apply(array, rest);
+}
+
+function inArray(array, value) {
+ for (var i in array) {
if (value == array[i]) {
return true;
}
}
+
return false;
}
-function getSet (array) {
+function getSet(array) {
var narray = [];
- for (i in array) {
- if ( !inArray(narray, array[i]) ) {
+
+ for (var i in array) {
+ if (!inArray(narray, array[i])) {
narray.push(array[i]);
}
}
+
return narray;
}
-function indexOf (array, v, offset) {
- for (i in array) {
+function indexOf(array, v, offset) {
+ for (var i in array) {
if (offset == undefined || i >= offset) {
- if ( !isNaN(i) && array[i] == v) {
+ if (!isNaN(i) && array[i] == v) {
return new Number(i);
}
}
}
+
return -1;
}
function rindexOf (array, v) {
var l = array.length;
- for (i in array) {
+
+ for (var i in array) {
if (!isNaN(i)) {
- var i = new Number(i)
+ var i = new Number(i);
}
+
if (!isNaN(i) && array[l - i] == v) {
return l - i;
}
}
+
return -1;
}
@@ -51,10 +67,12 @@ function compare (array, carray) {
if (array.length != carray.length) {
return false;
}
- for (i in array) {
+
+ for (var i in array) {
if (array[i] != carray[i]) {
return false;
}
}
+
return true;
}