Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

adjacent elements product javascript

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;
}
Comment

adjacent elements product javascript

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
Comment

adjacent elements product javascript

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]));
Comment

PREVIOUS NEXT
Code Example
Javascript :: input event on value changed 
Javascript :: last index of javascript 
Javascript :: group all items with same name js 
Javascript :: set _id to id 
Javascript :: Bots member count discord js 
Javascript :: express.urlencoded extended true or false 
Javascript :: react router dom private route 
Javascript :: do and tap operator rxjs 
Javascript :: javascript sleep 1 
Javascript :: how to randomize an array 
Javascript :: how to save and use item from local storage javascript 
Javascript :: js get class property 
Javascript :: click counter in js 
Javascript :: check for duplicates in array javascript 
Javascript :: get date one week from now javascript 
Javascript :: js how to check is array empty es6 
Javascript :: dom element set id 
Javascript :: javascript button onclick reload page 
Javascript :: javascript document.createElement add function 
Javascript :: react uselazyquery and usequery 
Javascript :: javascript onclick button 
Javascript :: path resolve in node js to current dir 
Javascript :: javascript queryselector 
Javascript :: js check if this last index in foreach 
Javascript :: sort array object 
Javascript :: javascript set input value by id 
Javascript :: react render after fetch 
Javascript :: focus element javascript 
Javascript :: get previous year in javascript 
Javascript :: return all elements of javascript array except the first item 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =