πŸ’Ž

ARR PS - sequence minimum position

notion image
Β 
notion image
Β 

풀어보기

λ¨Όμ € 배열을 Math.min λ©”μ„œλ“œμ— μŠ€ν”„λ ˆλ“œ μ—°μ‚°μžλ‘œ λ„˜κ²¨μ„œ μ΅œμ†Ÿκ°’μ„ ꡬ해둔닀.
λ°°μ—΄ λ‚΄ μ΅œμ†Ÿκ°’μ„ λ§Œλ‚  λ•Œλ§ˆλ‹€ result에 λ‹΄μ•„μ€€λ‹€.
Β 
function answer(nums) {
    let result = [];
    let min = Math.min(...nums);
    console.log(nums.forEach((v, i) => v === min && result.push(i)));

    return result;
}