Array 함수(Array.prototype 객체에 있는 함수)를 작성해야 합니다. 함수는 시작 인덱스와 끝 인덱스를 가져와야 하고 배열의 시작 인덱스에서 끝 인덱스까지 모든 요소를 합해야 합니다(시작 및 끝 포함)
예시
const arr = [1, 2, 3, 4, 5, 6, 7];
const sumRange = function(start = 0, end = 1){
const res = [];
if(start > end){
return res;
};
for(let i = start; i <= end; i++){
res.push(this[i]);
};
return res;
};
Array.prototype.sumRange = sumRange;
console.log(arr.sumRange(0, 4)); 출력
콘솔의 출력은 -
[ 1, 2, 3, 4, 5 ]