scrimba
Note at 1:12
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 1:12
by Hil
AboutCommentsNotes
Note at 1:12
by Hil
Expand for more info
main.js
run
preview
console
function adjacentElementsProduct(nums) {
// write code here.
let newArray = [];
let product = 0;

// filter out the null value
function numbersOnly(value) {
if (typeof (value) === 'number') {
return value;
}
}

for (let i = 0; i < nums.length; i++) {
product = nums[i] * nums[i+1];
newArray.push(product);
}

return newArray.filter(numbersOnly).reduce((a, b) => Math.max(a, b));
}



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