DEV Community

Cover image for Day 10 of JavaScriptmas - Adjacent Elements Product Solution
Sekti Wicaksono
Sekti Wicaksono

Posted on

Day 10 of JavaScriptmas - Adjacent Elements Product Solution

Day 10 is finding the biggest adjacent element of product in an array.

For example an array [3,6,-2,-5,7,3] the output should be 21 because 7*3=21 is the biggest adjcent product in an array.

This is JavaScript solution

function adjacentElementsProduct(nums) {

    let biggest = 0;

    for (let i = 0; i < nums.length; i++) {
        if(biggest < nums[i]*nums[i+1]) {
            biggest = nums[i]*nums[i+1];
        }        
    }

    return biggest;
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

ACI image

ACI.dev: Best Open-Source Composio Alternative (AI Agent Tooling)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Star our GitHub!