Valid Mountain Array
In this lab, you will be implementing a function to check if a given array of integers represents a valid mountain array or not. You will be using ESM import/export everywhere. Make sure to follow all the rules mentioned above while building the lab.
A valid mountain array is an array that follows these rules:
arr.length >= 3
- There exists some
0 < i < arr.length - 1such that:
arr < arr < ... < arr[i - 1] < arr[i]
arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
arr = [2, 1], the output should be
falseas the length of the array is less than 3.
arr = [3, 5, 5], the output should be
falsebecause the values don't strictly decrease after the peak value.
arr = [0, 3, 2, 1], the output should be
trueas it satisfies all the conditions of a valid mountain array.
- Write a function
validMountainArraythat receives an array of integers as input and returns
trueif it is a valid mountain array, otherwise
- Export the
validMountainArrayfunction from your code file.