scrimba
Note at 0:47
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:47
AboutCommentsNotes
Note at 0:47
Expand for more info
main.js
run
preview
console
const adjacentElementsProduct = nums => Math.max(...nums.map((c, i, a) => a[i+1] && [c, a[i+1]]).filter(e => Array.isArray(e)).map(e => e[0] * e[1]))



// function pairwise(arr, func){
// for(var i=0; i < arr.length - 1; i++){
// func(arr[i], arr[i + 1])
// }
// }

// pairwise(arr, function(current, next){
// console.log(current, next)
// })



/**
* Test Suite
*/
describe('adjacentElementsProduct()', () => {
it('returns largest product of adjacent values', () => {
// arrange
const nums = [3, 6, -2, -5, 7, 3];

// act
const result = adjacentElementsProduct(nums);

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

// assert
expect(result).toBe(21);
});
});
Console
"result: "
,
21
,
/index.html
LIVE