Filtering optimisations

This commit is contained in:
Jermolene
2014-04-05 17:31:36 +01:00
parent b7f674c51a
commit 272a4bbe61
4 changed files with 34 additions and 30 deletions

View File

@@ -35,21 +35,34 @@ exports.count = function(object) {
/*
Push entries onto an array, removing them first if they already exist in the array
array: array to modify
array: array to modify (assumed to be free of duplicates)
value: a single value to push or an array of values to push
*/
exports.pushTop = function(array,value) {
var t,p;
if($tw.utils.isArray(value)) {
// Remove any array entries that are duplicated in the new values
for(t=0; t<value.length; t++) {
p = array.indexOf(value[t]);
if(p !== -1) {
array.splice(p,1);
if(value.length !== 0) {
if(array.length !== 0) {
if(value.length < array.length) {
for(t=0; t<value.length; t++) {
p = array.indexOf(value[t]);
if(p !== -1) {
array.splice(p,1);
}
}
} else {
for(t=array.length-1; t>=0; t--) {
p = value.indexOf(array[t]);
if(p !== -1) {
array.splice(t,1);
}
}
}
}
// Push the values on top of the main array
array.push.apply(array,value);
}
// Push the values on top of the main array
array.push.apply(array,value);
} else {
p = array.indexOf(value);
if(p !== -1) {