Last active
February 3, 2016 15:10
-
-
Save iCloud/9904d7940c2bbfd620c8 to your computer and use it in GitHub Desktop.
Snippets for CodeWars
This file contains 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
// Arrays | |
Array.prototype.square = function () { return this.map(function(n) { return n*n; }); } | |
Array.prototype.cube = function () { return this.map(function(n) { return n*n*n; }); } | |
Array.prototype.average = function () { return this.sum() / this.length; } | |
Array.prototype.sum = function () { return this.reduce(function(a, b) { return a + b; }, 0); } | |
Array.prototype.even = function () { return this.filter(function(item) { return 0 == item % 2; }); } | |
Array.prototype.odd = function () { return this.filter(function(item) { return 0 != item % 2; }); } | |
Array.prototype.max = function () { return Math.max.apply(null, this); } | |
Array.prototype.min = function () { return Math.min.apply(null, this); } | |
//Arguments to array | |
var array = Array.prototype.slice.call(arguments, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment