Requires

Provides

Array.Extras.js

Extends the Array native object to include useful methods to work with arrays.

License:
MIT-style license
Authors:
Christoph Pojer, Sebastian Markbåge
  1. 24
  2. 25
  3. 26
  4. 27
  5. 28
  6. 29
  7. 30
  8. 31
  9. 32
  10. 33
  11. 34
  12. 35
  13. 36
  14. 37
  15. 38
  16. 39
  17. 40
  18. 41
  19. 42
  20. 43
  21. 44
  22. 45
  23. 46
  24. 47
  25. 48
  26. 49
  27. 50
  28. 51
  29. 52
  30. 53
  31. 54
  32. 55
  33. 56
  34. 57
  35. 58
  36. 59
  37. 60
  38. 61
  39. 62
  40. 63
  41. 64
  42. 65
  43. 66
  44. 67
  45. 68
  46. 69
  47. 70
  48. 71
  49. 72
  50. 73
  51. 74
  52. 75
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){ var undefined; for (var i = 0, l = this.length; i < l; i++) if (i in this) value = value === undefined ? this[i] : fn.call(null, value, this[i], i, this); return value; }, reduceRight: function(fn, value){ var i = this.length, undefined; while (i--) if (i in this) value = value === undefined ? this[i] : fn.call(null, value, this[i], i, this); return value; } });