큐1 [프로그래머스][자바스크립트][Level2][카카오] 캐시 풀이 /** * 캐시.js * https://programmers.co.kr/learn/courses/30/lessons/17680?language=javascript */ const MISS = 5, HIT = 1; // 1 function solution(cacheSize, cities) { if (cacheSize === 0) return MISS * cities.length; // 2 let answer = 0; const cache = []; cities .map((city) => city.toLowerCase()) // 3 .forEach((city) => { const cityIdx = cache.indexOf(city); if (cityIdx > -1) { answer += HIT; // .. 2022. 2. 22. 이전 1 다음