moje | function adjacentElementsProduct(array) {
let maximum = -Infinity
for(let i=0;i<array.length;i++){
if(array[i+1] !== undefined){
const adjecentProduct = array[i]*array[i+1];
adjecentProduct > maximum ? maximum = adjecentProduct : null
}
}
return maximum
}
adjacentElementsProduct([5, 8]);
adjacentElementsProduct([1, 2, 3]);
adjacentElementsProduct([1, 5, 10, 9]);
adjacentElementsProduct([4, 12, 3, 1, 5]);
adjacentElementsProduct([5, 1, 2, 3, 1, 4]);
adjacentElementsProduct([3, 6, -2, -5, 7, 3]);
adjacentElementsProduct([9, 5, 10, 2, 24, -1, -48]);
adjacentElementsProduct([5, 6, -4, 2, 3, 2, -23]);
adjacentElementsProduct([-23, 4, -5, 99, -27, 329, -2, 7, -921]);
adjacentElementsProduct([5, 1, 2, 3, 1, 4]);
adjacentElementsProduct([1, 0, 1, 0, 1000]);
adjacentElementsProduct([1, 2, 3, 0]);
| ready |
ich | function adjacentElementsProduct(array) {
let newArr = []
for(i=0; i < array.length-1; i++){
newArr.push(array[i]*array[i+1])
}
return Math.max(...newArr)
}
adjacentElementsProduct([5, 8]);
adjacentElementsProduct([1, 2, 3]);
adjacentElementsProduct([1, 5, 10, 9]);
adjacentElementsProduct([4, 12, 3, 1, 5]);
adjacentElementsProduct([5, 1, 2, 3, 1, 4]);
adjacentElementsProduct([3, 6, -2, -5, 7, 3]);
adjacentElementsProduct([9, 5, 10, 2, 24, -1, -48]);
adjacentElementsProduct([5, 6, -4, 2, 3, 2, -23]);
adjacentElementsProduct([-23, 4, -5, 99, -27, 329, -2, 7, -921]);
adjacentElementsProduct([5, 1, 2, 3, 1, 4]);
adjacentElementsProduct([1, 0, 1, 0, 1000]);
adjacentElementsProduct([1, 2, 3, 0]);
| ready |
ich2 | function adjacentElementsProduct(a) {
return Math.max(...a.map((x,i)=>x*a[i+1]).slice(0,-1))
}
adjacentElementsProduct([5, 8]);
adjacentElementsProduct([1, 2, 3]);
adjacentElementsProduct([1, 5, 10, 9]);
adjacentElementsProduct([4, 12, 3, 1, 5]);
adjacentElementsProduct([5, 1, 2, 3, 1, 4]);
adjacentElementsProduct([3, 6, -2, -5, 7, 3]);
adjacentElementsProduct([9, 5, 10, 2, 24, -1, -48]);
adjacentElementsProduct([5, 6, -4, 2, 3, 2, -23]);
adjacentElementsProduct([-23, 4, -5, 99, -27, 329, -2, 7, -921]);
adjacentElementsProduct([5, 1, 2, 3, 1, 4]);
adjacentElementsProduct([1, 0, 1, 0, 1000]);
adjacentElementsProduct([1, 2, 3, 0]);
| ready |
ich3 | function adjacentElementsProduct(array) {
let max = array[0] * array[1]
for (let i = 1; i < array.length - 1; i++) {
max = Math.max(max, array[i] * array[i + 1])
}
return max
}
adjacentElementsProduct([5, 8]);
adjacentElementsProduct([1, 2, 3]);
adjacentElementsProduct([1, 5, 10, 9]);
adjacentElementsProduct([4, 12, 3, 1, 5]);
adjacentElementsProduct([5, 1, 2, 3, 1, 4]);
adjacentElementsProduct([3, 6, -2, -5, 7, 3]);
adjacentElementsProduct([9, 5, 10, 2, 24, -1, -48]);
adjacentElementsProduct([5, 6, -4, 2, 3, 2, -23]);
adjacentElementsProduct([-23, 4, -5, 99, -27, 329, -2, 7, -921]);
adjacentElementsProduct([5, 1, 2, 3, 1, 4]);
adjacentElementsProduct([1, 0, 1, 0, 1000]);
adjacentElementsProduct([1, 2, 3, 0]);
| ready |