Write a function called largestPair that takes an array of integers and finds the pair of adjacent elements that has the largest product and return that product.
Answer the given question with a proper explanation and step-by-step solution.
JavaScript
DO NOT submit with any console.log statements in your file.
DO NOT edit the function definitions. You should simply write your code inside each function body. The functions are provided for you as a starting point in the submission-template.js file.
DO NOT create your own values inside the functions. We have a test suite which will pass in its own values. For example, in findSum, there is an array of numbers (called array) passed into the function as a parameter. You should work with array to write your solution. It's fine to pass your own values as you're working, but write the function body with the assumption that it should work against any appropriate values that are passed in.
Problem 4 -
Write a function called largestPair that takes an array of integers and finds the pair of adjacent elements that has the largest product and return that product. For example:
largestPair([5, 1, 2, 3, 1, 4]); // 6 largestPair([9, 5, 10, 2, 24, -1, -48]) // 50
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images