scrimba
Solution for day 10 of #javascriptmas
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

Solution for day 10 of #javascriptmas
AboutCommentsNotes
Solution for day 10 of #javascriptmas
Expand for more info
main.js
run
preview
console
function adjacentElementsProduct(nums) {
let maxProd = -Infinity;
for (let i = 0, j = i + 1; i < nums.length - 1; i++, j++) {
let currProd = nums[i] * nums[j];
if (currProd > maxProd) {
maxProd = currProd;
}
}
return maxProd;
}



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