scrimba
Note at 0:44
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 0:44
AboutCommentsNotes
Note at 0:44
Expand for more info
main.js
run
preview
console
const byTwo = a => {
const r = []
for(let i = 0; i < a.length; i++){
if(i < a.length - 1 ){
r.push([a[i], a[i + 1]])
}
}
return r
}


const arrayMaximalAdjacentDifference = nums => Math.max(...nums.map((c, i, a) => a[i+1] && [c, a[i+1]]).filter(e => Array.isArray(e)).map(a => Math.abs(a[0] - a[1])))



/**
* Test Suite
*/
describe('arrayMaximalAdjacentDifference()', () => {
it('returns largest difference between adjacent values', () => {
// arrange
const nums = [2, 4, 1, 0];

// act
const result = arrayMaximalAdjacentDifference(nums);

// log
console.log("result 1: ", result);

// assert
expect(result).toBe(3);
});

it('returns largest difference between adjacent values example 2', () => {
// arrange
const nums = [2, 9, 1, 0];

// act
const result = arrayMaximalAdjacentDifference(nums);

// log
console.log("result 2: ", result);

// assert
expect(result).toBe(8);
});
});
Console
"result 1: "
,
3
,
"result 2: "
,
8
,
/index.html
LIVE