
์ต๋น๊ฐ์ ์ฃผ์ด์ง ๊ฐ ์ค์์ ๊ฐ์ฅ ์์ฃผ ๋์ค๋ ๊ฐ์ ์๋ฏธํฉ๋๋ค. ์ ์ ๋ฐฐ์ด array๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋, ์ต๋น๊ฐ์ return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด๋ณด์ธ์. ์ต๋น๊ฐ์ด ์ฌ๋ฌ ๊ฐ๋ฉด -1์ return ํฉ๋๋ค.
array์ ๊ธธ์ด < 100array์ ์์ < 1000| array | result | 
|---|---|
| [1, 2, 3, 3, 3, 4] | 3 | 
| [1, 1, 2, 2] | -1 | 
| [1] | 1 | 
์ ์ถ๋ ฅ ์ #1
์ ์ถ๋ ฅ ์ #2
์ ์ถ๋ ฅ ์ #3
function solution(array) {
    // ์๋ฃ์ฌ์  ์์ฑ
    const dict = {0:0}
    // ๋ฐฐ์ด ๋ด์ ์๊ฐ ๋ฑ๋ก๋์ด์๋ค๋ฉด ++, ์๋๋ผ๋ฉด 1๋ก ๋ฑ๋ก
    array.forEach(item => {
        dict[item] = dict[item] ? ++dict[item] : 1
    })
    // ์ ์ผ ํฐ ๊ฐ ๋ฐ ํด๋น ๊ฐ์ ๋ด์ ์ธ๋ฑ์ค ์ค๋น
    const max = Math.max(...Object.values(dict))
    let idx = 0
    // ์ต๋๊ฐ์ด 2๊ฐ ์ด์์ด๋ผ๋ฉด -1์ ๋ฐํํ๋ฉฐ ์๋๋ผ๋ฉด, ์ต๋๊ฐ์ ์ธ๋ฑ์ค๋ฅผ ์ ์ฅ
    if(Object.values(dict).filter(a => a === max).length !== 1) {
        return -1
    } else {
        Object.values(dict).forEach((a,i) => a === max ? idx=i : null)
    }
    // ๋ฐํ
    return Number(Object.keys(dict)[idx])
}