Given an array of integers, find the pair of adjacent elements that has the largest product and return that product

前端 未结 5 1978
情书的邮戳
情书的邮戳 2021-01-19 12:22

Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.

and here is my code

function ad         


        
5条回答
  •  孤街浪徒
    2021-01-19 12:49

    This is quite simple actually

    function adjacentElementsProduct(inputArray) {
        let max = -Infinity;
        for (let i = 1; i < inputArray.length; i++) {
            max = Math.max(inputArray[i] * inputArray[i - 1], max);
        }
    
        return max;
    }
    

提交回复
热议问题