본문 바로가기

프로그래머스 - 코딩테스트

[JavaScript][코딩테스트] 첫 번째로 나오는 음수


간단하다.

 

findIndex 라는 JS 함수를 사용하면 된다.

 

function solution(num_list) {
    return num_list.findIndex(d => d < 0);
}

const answer = solution([12, 4, 15, 46, 38, -2, 15]);

console.log("answer check >>> " , answer); 
// answer check >>> 5