function solution(inputArray) {
let max = inputArray[0] * inputArray[1];
for (let i = 1; i < inputArray.length - 1; i++) {
let product = inputArray[i] * inputArray[i + 1];
if (product > max) {
max = product;
}
}
return max;
}
function adjacentElementsProduct(arr) {
return Math.max(...arr.slice(0, -1).map((n, i) => n * arr[i + 1]))
}
console.log(adjacentElementsProduct([3, 6, -2, -5, 7, 3]));
Run code snippet
function adjacentElementsProduct(items) {
var product = 0;
for (var i = 0; i < items.length - 1; i++) {
product = Math.max(product, items[i] * items[i + 1]);
}
return product;
}
console.log(adjacentElementsProduct([3, 6, -2, -5, 7, 3]));