diff --git "a/dongmin/\353\215\224 \353\247\265\352\262\214.js" "b/dongmin/\353\215\224 \353\247\265\352\262\214.js" new file mode 100644 index 0000000..b7dc8be --- /dev/null +++ "b/dongmin/\353\215\224 \353\247\265\352\262\214.js" @@ -0,0 +1,18 @@ +function solution(scoville, K) { + let count = 0; + const hash = scoville.reduce((a, b) => { + a[b] = b; + return a; + }, {}); + + while (Object.values(hash)[0] < K) { + const arr = Object.values(hash); + const newFood = arr[0] + arr[1] * 2; + delete hash[arr[0]]; + delete hash[arr[1]]; + count += 1; + hash[newFood] = newFood; + } + + return count; +}