implementing vanilla array_difference function

10.3.x-maintenance
cTn 2013-11-20 12:24:37 +01:00
parent 5427d18438
commit 0eaa88aea3
1 changed files with 18 additions and 0 deletions

18
main.js
View File

@ -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;
}