Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3주차] 부록 #13

Open
bread1022 opened this issue Mar 12, 2024 · 0 comments
Open

[3주차] 부록 #13

bread1022 opened this issue Mar 12, 2024 · 0 comments

Comments

@bread1022
Copy link
Contributor

주제

부록 연습 문제 #12

책 내용 (p123~131)

  1. 비교 연습하기
const dayStart = '07:30';
const dayEnd = '17:45';

// 회의가 근무시간 내에 이루어질 경우 true, 그렇지 않으면 false
function scheduleMeeting(input, duration) {
  // hour, min 을 나눠서 min + duration = sum
  const [hour, min] = input.split(':').map(Number);
  const sum = min + duration;

  const [inputHour, inputMin] = sum >= 60 ? [hour + 1, sum - 60] : [hour, sum];

  const [startHour, startMin] = dayStart.split(':').map(Number);
  const [endHour, endMin] = dayEnd.split(':').map(Number);

  return (
    ((hour === startHour && min >= startMin) || hour > startHour) &&
    ((inputHour === endHour && inputMin <= endMin) || inputHour < endHour)
  );
}
  1. 클로저 연습하기
function range(start, end) {
  if (end === undefined) {
    return (end) => range(start, end);
  }
  return Array.from({ length: end - start + 1 }, (_, i) => i + start);
}
  1. 프로토타입 연습하기
var slotMachine = {
  reels: [Object.create(reel), Object.create(reel), Object.create(reel)],
  spin() {
    this.reels.forEach(function spinReel(reel) {
      reel.spin();
    });
  },
  // 나머지 연산자를 사용하면 원형으로 만들 수 있음?
  // 위임을 해서 position을 관리하기
  display() {
    // 배열화 해서 join('|')해야겠음
    // 슬롯 머신의 릴은 결과 해당하는 기호 하나 position과 position -1 , position +1을 함께 표시
    // const result = [reel.position - 1, reel.position, reel.position + 1];
    // return result.join('|'); 죄송한데 모르겠다요'ㅅ'리얼
  },
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant