[Pkg-javascript-commits] [sockjs-client] 266/434: `arrSkip` util function

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:18 UTC 2014


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch master
in repository sockjs-client.

commit e447a6b7138b0c93eb22ff081a0261fbf66999ee
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Thu Jan 5 16:18:25 2012 +0000

    `arrSkip` util function
---
 lib/utils.js                    | 10 ++++++++++
 tests/html/src/unittests.coffee |  8 ++++++++
 2 files changed, 18 insertions(+)

diff --git a/lib/utils.js b/lib/utils.js
index b9b7918..8b65842 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -93,6 +93,16 @@ utils.arrIndexOf = function(arr, obj){
     return -1;
 };
 
+utils.arrSkip = function(arr, obj) {
+    var idx = utils.arrIndexOf(arr, obj);
+    if (idx === -1) {
+        return arr.slice();
+    } else {
+        var dst = arr.slice(0, idx);
+        return dst.concat(arr.slice(idx+1));
+    }
+};
+
 utils.delay = function(t, fun) {
     if(typeof t === 'function') {
         fun = t;
diff --git a/tests/html/src/unittests.coffee b/tests/html/src/unittests.coffee
index 415ddcb..b102c2c 100644
--- a/tests/html/src/unittests.coffee
+++ b/tests/html/src/unittests.coffee
@@ -60,6 +60,14 @@ test 'arrIndexOf', ->
     equal(u.arrIndexOf(a, null), -1)
     equal(u.arrIndexOf(a, 6), -1)
 
+test 'arrSkip', ->
+    a = [1,2,3,4,5]
+    deepEqual(u.arrSkip(a, 1), [2,3,4,5])
+    deepEqual(u.arrSkip(a, 2), [1,3,4,5])
+    deepEqual(u.arrSkip(a, 11), [1,2,3,4,5])
+    deepEqual(u.arrSkip(a, 'a'), [1,2,3,4,5])
+    deepEqual(u.arrSkip(a, '1'), [1,2,3,4,5])
+
 test 'quote', ->
     equal(u.quote(''), '""')
     equal(u.quote('a'), '"a"')

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list