처음에 스스로 만들었을 때는 배열을 따로 만들지 않았고 중복을 피하기 위해 while 문을 돌렸다. 하지만 이 방법이 훨씬 효율적인 것 같다.
const numbers = Array(9)
  .fill()
  .map((v, i) => i + 1);
console.log(numbers);
for (let i = 0; i < 4; i++) {
  const index = Math.floor(Math.random() * numbers.length);
  answer.push(numbers[index]);
  numbers.splice(index, 1);
}
for 문을 돌려서 1부터 9까지 담긴 배열을 만들 수 있지만 배열의 메서드를 사용하는 것을 책에서 추천해 주었다.
0-9까지 담긴 배열을 만든 뒤 하나씩 랜덤으로 하나씩 뽑고 뽑은 것은 중복을 피하기 위해 삭제해 준다
const checkValidity = (input) => {
  if (input.length !== 4) return alert("숫자 4개를 입력하세요");
  if (tries.includes(input)) return alert("이미 입력하신 숫자입니다");
  if (new Set(input).size !== 4)
    return alert("4가지 다른 숫자를 입력해 주세요");
  return true;
};
- 제일 간단한 것부터 if 문으로 check 해준다
 - alert 함수는 undefined을 return 하므로 if문으로는 false가 된다.
 - new Set()은 중복을 허용하지 않는 특수한 배열이다
 - new Set('1234')을 하면 Set 내부에는 1,2,3만 들어간다
 
또한 Set의 요소 개수를 구할 때는 length가 아니라 size를 사용한다
const getResult = (input) => {
  const result = { strike: 0, ball: 0, out: 0 };
  answer.forEach((number, aIndex) => {
    const index = input.indexOf(String(number));
    if (index > -1) {
      if (index === aIndex) result.strike++;
      else result.ball++;
    }
  });
  return result;
};
입력한 값이 몇개의 스트라이크와 몇개의 볼을 가지는지 판단해서 return 하는 함수이다