Created
December 19, 2023 09:13
-
-
Save JoshuaRotimi/9b86140d29e5a3e1ccbbfe5dd0668b3a to your computer and use it in GitHub Desktop.
Write a function that determines if an array of numbers is a bitonic sequence.
This file contains hidden or 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
| const isBitonic = (arr) => { | |
| let peakNumber = 0; | |
| for (let i = 0; i < arr.length; i++) { | |
| if(arr[i] > peakNumber) { | |
| peakNumber = arr[i]; | |
| } | |
| if(arr[i] === peakNumber && arr[i] > arr[i + 1]) { | |
| console.log('extra credit: ', peakNumber); | |
| return true | |
| } | |
| } | |
| console.log('extra credit: ', peakNumber); | |
| return false | |
| } | |
| isBitonic([1,2,3,2,5]); | |
| isBitonic([1,2,3]) | |
| isBitonic([3,4,5,5,5,2,1,7]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment