forked from bnowel/NodeWorld
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6f746b
commit 0ae131c
Showing
8 changed files
with
86 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var helper = { | ||
getFirstArrayElementIndexByPrpertyValue : function(arrIn, prop, val){ | ||
var i = -1, | ||
indexes = this.getIndexesByPrpertyValue(arrIn, prop, val); | ||
|
||
if (indexes.length > 0) { | ||
i = indexes[0]; | ||
} | ||
|
||
return i; | ||
}, | ||
getIndexesByPrpertyValue : function(arrIn, prop, val){ | ||
var len = arrIn.length, | ||
indexes = []; | ||
if (len!=0){ | ||
for (var i=0;i<len;i++){ | ||
var el = arrIn[i]; | ||
if (el.hasOwnProperty(prop) && el[prop] === val){ | ||
indexes.push(i); | ||
} | ||
} | ||
} | ||
return indexes; | ||
} | ||
} | ||
|
||
if (typeof exports !== 'undefined') { | ||
if (typeof module !== 'undefined' && module.exports) { | ||
exports = module.exports = helper; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var assert = require('assert') | ||
,helper = require("./helper") | ||
|
||
if (typeof module !== "undefined" && module === require.main) { | ||
var suiteExports = {}; | ||
var suite = function(a, fun){ | ||
fun(); | ||
module.exports = suiteExports; | ||
require("asyncjs").test.testcase(module.exports).exec() | ||
} | ||
|
||
var test = function(txt, testfun){ | ||
suiteExports["test "+ txt] = testfun; | ||
} | ||
|
||
|
||
} | ||
|
||
var testArr = [ | ||
{}, | ||
{name:"findme"}, | ||
{name:"findme", info: "I'm different"} | ||
]; | ||
|
||
suite('Helper', function() { | ||
test('find first index of test elem with name "findme"', function() { | ||
assert.equal(helper.getFirstArrayElementIndexByPrpertyValue(testArr, "name", "findme"), 1); | ||
}); | ||
test('find no first elem with name:"dontfindme"', function() { | ||
assert.equal(helper.getFirstArrayElementIndexByPrpertyValue(testArr, "name", "dontfindme"), -1); | ||
}); | ||
test('find no elem with name:"dontfindme"', function() { | ||
assert.deepEqual(helper.getIndexesByPrpertyValue(testArr, "name", "dontfindme"), []); | ||
}); | ||
test('find all elem with name:"findme"', function() { | ||
assert.deepEqual(helper.getIndexesByPrpertyValue(testArr, "name", "findme"), [1,2]); | ||
}); | ||
}); | ||
|
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters