Sha256: 00d8efcd77811889c943ad2047699f95326d1e3d31bad077224deb228e90a6d5
Contents?: true
Size: 1.28 KB
Versions: 7
Compression:
Stored size: 1.28 KB
Contents
/* --- script: Array.Extras.js name: Array.Extras description: Extends the Array native object to include useful methods to work with arrays. license: MIT-style license authors: - Christoph Pojer - Sebastian Markbåge requires: - Core/Array - MooTools.More provides: [Array.Extras] ... */ (function(nil){ Array.implement({ min: function(){ return Math.min.apply(null, this); }, max: function(){ return Math.max.apply(null, this); }, average: function(){ return this.length ? this.sum() / this.length : 0; }, sum: function(){ var result = 0, l = this.length; if (l){ while (l--) result += this[l]; } return result; }, unique: function(){ return [].combine(this); }, shuffle: function(){ for (var i = this.length; i && --i;){ var temp = this[i], r = Math.floor(Math.random() * ( i + 1 )); this[i] = this[r]; this[r] = temp; } return this; }, reduce: function(fn, value){ for (var i = 0, l = this.length; i < l; i++){ if (i in this) value = value === nil ? this[i] : fn.call(null, value, this[i], i, this); } return value; }, reduceRight: function(fn, value){ var i = this.length; while (i--){ if (i in this) value = value === nil ? this[i] : fn.call(null, value, this[i], i, this); } return value; } }); })();
Version data entries
7 entries across 7 versions & 1 rubygems