1const cutOffFirstAndLastFive = (array) => {
2 const [first, ...rest] = array;
3 return rest.slice(-5);
4}
5
6cutOffFirstAndLastFive([1, 55, 77, 88]);
7
8console.log(
9 'Tests:',
10 JSON.stringify(cutOffFirstAndLastFive([1, 55, 77, 88])),
11 JSON.stringify(cutOffFirstAndLastFive([1, 55, 77, 88, 99, 22, 33, 44])),
12 JSON.stringify(cutOffFirstAndLastFive([1]))
13);
1var arr1 = [0, 1, 2, 3, 4, 5, 6, 7],
2 arr2 = [0, 1, 2, 3];
3
4document.body.innerHTML = 'ARRAY 1: ' + arr1.slice(1).slice(-5) + '<br/>ARRAY 2: ' + arr2.slice(1).slice(-5);