function adjacentElementsProduct(nums) {
// write code here.
if (nums.length == 0){
return 0
}
if (nums.length == 1){
return nums[0] * nums[0]
}
let max = nums[0]*nums[1]
for(let i=0; i<nums.length-1; i++){
if (nums[i]*nums[i+1] > max){
max = nums[i]*nums[i+1]
}
}
return max;
}
/**
* 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);
});
});