Skip to content

Instantly share code, notes, and snippets.

@maousan
Last active February 24, 2016 13:32
Show Gist options
  • Select an option

  • Save maousan/ac5e4635c6c6cf498309 to your computer and use it in GitHub Desktop.

Select an option

Save maousan/ac5e4635c6c6cf498309 to your computer and use it in GitHub Desktop.
array concat deeply!
var jqStyleAdd = function(arr, value) {
var i = 0, len = arr.length;
(function addClass(value, flags) {
if (typeof value === "function") {
arr.forEach(function(elem, j){
i = j;
addClass(value.call(elem, j, elem), true);
});
} else if (value) {
arr[i] = value;
if (!flags) {
i++;
while (i != len) {
arr[i++] = value;
}
}
}
})(value);
};
var arr = [1,2,3,4];
jqStyleAdd(arr, function(i, value){
return this + 100;
});
console.log(arr);
jqStyleAdd(arr, function(i, value){
return this + 200;
});
console.log(arr);
jqStyleAdd(arr, 100);
console.log(arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment