JSFiddle - React, Tailwind, and code Playground
by Jessie Lau
HTML
Array.range(start, count) should return an array containing 'count' numbers from 'start' to 'start + count' Example: Array.range(0, 3) returns [0, 1, 2]
Array.sum() return the sum of all numbers in the array Example: [0, 1, 2].sum() returns 3 Example: Array.range(-1,4).sum() should return 2
While not forbidden try to write both function without using a for loop
JavaScript
Array.range = function (start, count) {
var myArr = [];
for (var i = start; i < start+count; i++) {
myArr.push(i);
}
return myArr;
}
Array.prototype.sum = function() {
return this.reduce(function(a,b){return a+b});
}
console.log(Array.range(-1,0).sum());