implementing vanilla array_difference function
parent
5427d18438
commit
0eaa88aea3
18
main.js
18
main.js
|
@ -87,4 +87,22 @@ function microtime() {
|
|||
var now = new Date().getTime() / 1000;
|
||||
|
||||
return now;
|
||||
}
|
||||
|
||||
// accepting single level array with "value" as key
|
||||
function array_difference(firstArray, secondArray) {
|
||||
var cloneArray = [];
|
||||
|
||||
// create hardcopy
|
||||
for (var i = 0; i < firstArray.length; i++) {
|
||||
cloneArray.push(firstArray[i]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < secondArray.length; i++) {
|
||||
if (cloneArray.indexOf(secondArray[i]) != -1) {
|
||||
cloneArray.splice(cloneArray.indexOf(secondArray[i]), 1);
|
||||
}
|
||||
}
|
||||
|
||||
return cloneArray;
|
||||
}
|
Loading…
Reference in New Issue