int adjacentElementsProduct(int[] inputArray) {
//The Select method changes each element in the result
// i is the element in the array and j is the current index
// If j is greater than 0, take the value of i * inputArray[j-1], i * (value in the previous position)
// If j es less or equal to 0, take the value of int.MinValue (-2147483648)
// From the resulting IEnumerable, return the item with the max value
return inputArray.Select((i, j) => j > 0 ? i * inputArray[j-1] : int.MinValue).Max();
}
function adjacentElementsProduct(inputArray) {
// ... - This is the spread operator, and it essentially takes either an array or an object and expands it into its set of items.
// map() – returns a new list with the result of each item in an array
return Math.max(...inputArray.slice(1).map((x,i)=>[x*inputArray[i]]));
}
def adjacentElementsProduct(inputArray):
return max([inputArray[i] * inputArray[i+1] for i in range(len(inputArray)-1)])
# Description:
Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.