scrimba
Note at 0:01
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:01
by
AboutCommentsNotes
Note at 0:01
by
Expand for more info
main.js
run
preview
console
const adjacentElementsProduct=(nums,i)=>nums
.map((item,i2)=>item * nums[i2+1])//[18, -12, 10, -35, 21, null]
.filter(item=>item)
.reduce((acc,cur)=>acc>cur? acc:cur,1)




//alternative to reduce using sort and returning the first element //

// const adjacentElementsProduct=(nums,i)=>nums
// .map((item,i)=>item * nums[i-1])
// .filter(item=>item).sort((a,b)=>b-a)[0]

/**
* 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