https://programmers.co.kr/learn/courses/30/lessons/42588
function solution(heights) {
var answer = [];
var length = heights.length;
var getTopIndex = 0;
for(var i =length-1; i>0; i--){
var compare = heights[i];
var subArr = heights.slice(0,i);
var getTop = subArr.reverse().find(num => num > compare);
if(getTop !== undefined){
// getTopIndex = heights.indexOf(getTop)+1;
// 그냥 indexOf 쓰면 같은 숫자가 있을 때 문제가 된다...-> 가장 첫번째 index리턴하니까
subArr.reverse().map((num, i)=>{
if(num ===getTop){
getTopIndex = i+1;
}
});
}else{
getTopIndex = 0;
}
answer.unshift(getTopIndex);
}
answer.unshift(0);
return answer;
}