-
Notifications
You must be signed in to change notification settings - Fork 12
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
Showing
6 changed files
with
120 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var casting = require('./casting_type.js'); | ||
|
||
exports.array_merge = function (arr1, arr2) { | ||
var res, pro; | ||
if (casting.is_array(arr1) && casting.is_array(arr2)) { | ||
res = arr1.concat(arr2); | ||
} else if (casting.is_object(arr1) && casting.is_object(arr2)) { | ||
res = {}; | ||
for(pro in arr1) { | ||
res[pro] = arr1[pro]; | ||
} | ||
for(pro in arr2) { | ||
res[pro] = arr2[pro]; | ||
} | ||
} | ||
return res; | ||
}; |
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,29 @@ | ||
var phplikeMod = require('./include.js'); | ||
var assert = require("assert"); | ||
|
||
//mocha lib/ --grep mthod_get | ||
describe('Test method: array_merge', function() { | ||
it('merge index array', function() { | ||
var arr1 = [1], arr2 = [2]; | ||
var res = phplikeMod.array_merge(arr1, arr2); | ||
assert.equal(1, res[0]); | ||
assert.equal(2, res[1]); | ||
assert.equal("undefined", typeof(arr1[1])); | ||
|
||
|
||
}); | ||
it('merge assoc array', function() { | ||
var arr1 = {"a": "b"}, arr2 = {"c": "d"}; | ||
var res = phplikeMod.array_merge(arr1, arr2); | ||
|
||
assert.equal("b", res["a"]); | ||
assert.equal("d", res["c"]); | ||
assert.equal("undefined", typeof(arr1["c"])); | ||
|
||
|
||
}); | ||
|
||
|
||
}); | ||
|
||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
//require('./../nodejs/index.js'); | ||
global.UNIT_TEST = true; | ||
|
||
var module = require('./../module.js'); | ||
|
||
|