Advertisement
kstoyanov

01. Array Extension

Oct 16th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function solve() {
  2.     Array.prototype.last = function () {
  3.         return this[this.length - 1];
  4.     };
  5.  
  6.     Array.prototype.skip = function (n) {
  7.         return this.slice(n);
  8.     };
  9.  
  10.     Array.prototype.take = function (n) {
  11.         return this.slice(0, n);
  12.     };
  13.  
  14.     Array.prototype.sum = function (n) {
  15.         return this.reduce((acc, x) => acc + x, 0);
  16.     };
  17.  
  18.     Array.prototype.average = function (n) {
  19.         return this.sum() / this.length;
  20.     };
  21. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement