Skip to content

Instantly share code, notes, and snippets.

@boxxxie
Created September 29, 2011 05:49
Show Gist options
  • Save boxxxie/1250067 to your computer and use it in GitHub Desktop.
Save boxxxie/1250067 to your computer and use it in GitHub Desktop.
isArray = function(obj) {
return toString.call(obj) === '[object Array]';
};
const flatten = function(arr) {
return arr.reduce(function(memo, value) {
if (isArray(value)) {
return memo.concat(flatten(value));
}
else {
memo[memo.length] = value;
return memo;
}
}, []);
};
Array.prototype.flatten = function(){
return flatten(this);
};
Array.prototype.contains = function(item){
return (this.indexOf(item) != -1);
};
module.exports = {
prototype : Array.prototype
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment