services/sync/tps/extensions/mozmill/resource/stdlib/arrays.js

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, you can obtain one at http://mozilla.org/MPL/2.0/. */
     5 var EXPORTED_SYMBOLS = ['inArray', 'getSet', 'indexOf',
     6                         'remove', 'rindexOf', 'compare'];
     9 function remove(array, from, to) {
    10   var rest = array.slice((to || from) + 1 || array.length);
    11   array.length = from < 0 ? array.length + from : from;
    13   return array.push.apply(array, rest);
    14 }
    16 function inArray(array, value) {
    17   for (var i in array) {
    18     if (value == array[i]) {
    19       return true;
    20     }
    21   }
    23   return false;
    24 }
    26 function getSet(array) {
    27   var narray = [];
    29   for (var i in array) {
    30     if (!inArray(narray, array[i])) {
    31       narray.push(array[i]);
    32     }
    33   }
    35   return narray;
    36 }
    38 function indexOf(array, v, offset) {
    39   for (var i in array) {
    40     if (offset == undefined || i >= offset) {
    41       if (!isNaN(i) && array[i] == v) {
    42         return new Number(i);
    43       }
    44     }
    45   }
    47   return -1;
    48 }
    50 function rindexOf (array, v) {
    51   var l = array.length;
    53   for (var i in array) {
    54     if (!isNaN(i)) {
    55       var i = new Number(i);
    56     }
    58     if (!isNaN(i) && array[l - i] == v) {
    59       return l - i;
    60     }
    61   }
    63   return -1;
    64 }
    66 function compare (array, carray) {
    67   if (array.length != carray.length) {
    68     return false;
    69   }
    71   for (var i in array) {
    72     if (array[i] != carray[i]) {
    73       return false;
    74     }
    75   }
    77   return true;
    78 }

mercurial