Skip to content

Commit

Permalink
add challenge solution in js for Adjacent element product challenge a…
Browse files Browse the repository at this point in the history
…nd it's image
  • Loading branch information
Brnd08 committed Jul 18, 2023
1 parent f95a326 commit 54cf2bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions AdjacentElementsProduct/adjacent_elements_product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function solution (inputArray){
var maxProduct = inputArray[0] * inputArray[1]
for(var i = 2; i < inputArray.length; i++){
let currentProduct = inputArray[i] * inputArray[i - 1]
maxProduct = currentProduct > maxProduct ? currentProduct : maxProduct
}
return maxProduct;
}
var inputArray = [1, 0, 1, 0, 1000]
console.log(`The max adjacent numbers product in the array [${inputArray}] is ${solution(inputArray)}`)
var inputArray2 = [3, 6, -2, -5, 7, 3];
console.log("The max adjacent numbers product in the array %s is %d", inputArray2, solution(inputArray2))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 54cf2bb

Please sign in to comment.