Good afternoon! Here's our prompt for today.
A peak element
is an element that is strictly greater than its neighbors.
Consider that we are given a list of numbers, such as the following:
[1, 2, 3, 1]
Determine the peak element
of this list, and return its index. If the array contains multiple peaks, return the index to any of the peaks.

Constraints
- 1 <=
nums.length
<= 1000 - -231 <=
nums[i]
<= 231 - 1 nums[i] != nums[i + 1]
for all validi
.
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx
22
var assert = require('assert');
​
function find_peak_element(arr) {
//fill this in
}
​
try {
assert.equal(find_peak_element([1, 2, 3, 1]), 2);
​
console.log('PASSED: ' + "assert.equal(find_peak_element([1,2,3,1]), 2)");
} catch (err) {
console.log(err);
}
​
try {
assert.equal([1, 5].includes(find_peak_element([1, 2, 1, 3, 5, 6, 4])), true);
​
console.log('PASSED: ' + "assert.equal([1, 5].includes(find_peak_element([1, 2, 1, 3, 5, 6, 4])), true)");
} catch (err) {
console.log(err);
}
​
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment
Here's our guided, illustrated walk-through.
How do I use this guide?
Access all course materials today
The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.