scrimba
Note at 0:42
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:42
AboutCommentsNotes
Note at 0:42
Expand for more info
main.js
run
preview
console
function adjacentElementsProduct(nums) {
// write code here.
return nums.reduce(function(acc, int, i, nums){
console.log(acc)
if(nums.length > i + 1){
return [
...acc,
int * nums[i + 1]
]
}else{
return acc;
}
}, []).reduce((acc, curValue) => {
return Math.max(acc, curValue)
})
}



/**
* 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
[]
,
[
18
]
,
[
18
,
-12
]
,
[
18
,
-12
,
10
]
,
[
18
,
-12
,
10
,
-35
]
,
[
18
,
-12
,
10
,
-35
,
21
]
,
"result: "
,
21
,
/index.html
LIVE