michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, you can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var EXPORTED_SYMBOLS = ['inArray', 'getSet', 'indexOf', michael@0: 'remove', 'rindexOf', 'compare']; michael@0: michael@0: michael@0: function remove(array, from, to) { michael@0: var rest = array.slice((to || from) + 1 || array.length); michael@0: array.length = from < 0 ? array.length + from : from; michael@0: michael@0: return array.push.apply(array, rest); michael@0: } michael@0: michael@0: function inArray(array, value) { michael@0: for (var i in array) { michael@0: if (value == array[i]) { michael@0: return true; michael@0: } michael@0: } michael@0: michael@0: return false; michael@0: } michael@0: michael@0: function getSet(array) { michael@0: var narray = []; michael@0: michael@0: for (var i in array) { michael@0: if (!inArray(narray, array[i])) { michael@0: narray.push(array[i]); michael@0: } michael@0: } michael@0: michael@0: return narray; michael@0: } michael@0: michael@0: function indexOf(array, v, offset) { michael@0: for (var i in array) { michael@0: if (offset == undefined || i >= offset) { michael@0: if (!isNaN(i) && array[i] == v) { michael@0: return new Number(i); michael@0: } michael@0: } michael@0: } michael@0: michael@0: return -1; michael@0: } michael@0: michael@0: function rindexOf (array, v) { michael@0: var l = array.length; michael@0: michael@0: for (var i in array) { michael@0: if (!isNaN(i)) { michael@0: var i = new Number(i); michael@0: } michael@0: michael@0: if (!isNaN(i) && array[l - i] == v) { michael@0: return l - i; michael@0: } michael@0: } michael@0: michael@0: return -1; michael@0: } michael@0: michael@0: function compare (array, carray) { michael@0: if (array.length != carray.length) { michael@0: return false; michael@0: } michael@0: michael@0: for (var i in array) { michael@0: if (array[i] != carray[i]) { michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: return true; michael@0: }