Created
September 29, 2011 05:49
-
-
Save boxxxie/1250067 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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