๋ฌธ์ œ

๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ๋‹ด์€ ๋ฐฐ์—ด lottos, ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ๋‹ด์€ ๋ฐฐ์—ด win_nums๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์ด๋•Œ, ๋‹น์ฒจ ๊ฐ€๋Šฅํ•œ ์ตœ๊ณ  ์ˆœ์œ„์™€ ์ตœ์ € ์ˆœ์œ„๋ฅผ ์ฐจ๋ก€๋Œ€๋กœ ๋ฐฐ์—ด์— ๋‹ด์•„์„œ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

 

 

์ฝ”๋“œ

const solution = (lottos, win_nums) => {
  let answer = [];

  let zeroCount = lottos.filter((el) => el === 0).length;
  let sameNums = lottos.filter((el) => win_nums.includes(el)).length;

  let min = 7 - sameNums >= 6 ? 6 : 7 - sameNums; // ์ตœ์ €์ˆœ์œ„
  let max = min - zeroCount < 1 ? 1 : min - zeroCount// ์ตœ๊ณ ์ˆœ์œ„

  answer = [max, min];
  return answer;
}

const lottos = [44, 1, 0, 0, 31, 25];
const win_nums = [31, 10, 45, 1, 6, 19];
console.log(solution(lottos, win_nums));

+ Recent posts