-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add challenge solution in js for Adjacent element product challenge a…
…nd it's image
- Loading branch information
Showing
2 changed files
with
12 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.