Created
June 19, 2019 22:09
-
-
Save restart916/e742f4f94a60c6dacb41ace5c6b607bc to your computer and use it in GitHub Desktop.
20190619_leetcode_852_PeakIndexinaMountainArray
This file contains 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
/** | |
* @param {number[]} A | |
* @return {number} | |
*/ | |
var peakIndexInMountainArray = function(A) { | |
let maxIndex = 0; | |
let index = 0; | |
A.reduce((a,c) => { | |
index++; | |
if (a < c) { maxIndex = index; } | |
return Math.max(a,c) | |
}); | |
return maxIndex; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reduce 나 map 모두 사실 인자가 뒤에 더 옵니다(보통 index 와 array 순으로 옵니다) 이것때문에 가끔 엉뚱한 연산결과를 내서 고통받는 경우도 있으니 주의하셔용,,,, (first class citizen + parameter에 기본값 undefined 가 꽂혀서 일어나는 JS만의 대환장쑈입니다...)