๋ฐ์ํ
๐ค๋ฌธ์ ํด๊ฒฐ
1. filter์ includes๋ฅผ ์ด์ฉํด์ ๋ก๋ ๋ฒํธ๊ฐ ๋น์ฒจ ๋ฒํธ์ ํฌํจ๋ ๊ฐ์๋ฅผ ๊ตฌํจ
2. filter๋ฅผ ์ด์ฉํด์ ๋ก๋ ๋ฒํธ์ 0์ ๊ฐ์๋ฅผ ๊ตฌํจ
3. ์ต์ ๋น์ฒจ ๊ฐ์๋ ๊ทธ๋ฅ ๋น์ฒจ ๊ฐ์
4. ์ต๋ ๋น์ฒจ ๊ฐ์๋ ์ต์ ๋น์ฒจ ๊ฐ์ + 0์ ๊ฐ์
5. ์์๋ฅผ ๊ตฌํจ
๐จ
๐ป์์ค ์ฝ๋
function solution(lottos, win_nums) {
var answer = [];
var minWinningCnt = lottos.filter(number => win_nums.includes(number)).length;
var maxWinningCnt = minWinningCnt + lottos.filter(number => number === 0).length;
var rank = [6, 6, 5, 4, 3, 2, 1];
answer = [rank[maxWinningCnt], rank[minWinningCnt]];
return answer;
}
console.log(solution([44, 1, 0, 0, 31, 25], [31, 10, 45, 1, 6, 19]));
console.log(solution([0, 0, 0, 0, 0, 0], [38, 19, 20, 40, 15, 25]));
console.log(solution([45, 4, 35, 20, 3, 9] , [20, 9, 3, 45, 4, 35]));
๐๋ฌธ์ ํ์ธ
์ถ์ฒ: ํ๋ก๊ทธ๋๋จธ์ค
๋ฐ์ํ