Skip to content

Commit

Permalink
feat: 각 코치가 못 먹는 음식을 입력받기
Browse files Browse the repository at this point in the history
- 여러 시도 끝에 콜백으로 처리함
  • Loading branch information
gabrielyoon7 committed Dec 17, 2022
1 parent e7570f5 commit c6dad71
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Coach } = require('./models/Coach');
const { readCoaches } = require('./views/InputView');
const { readCoaches, readBannedFoods } = require('./views/InputView');
const { OutputView } = require('./views/OutputView');

class App {
Expand All @@ -10,12 +10,23 @@ class App {
readCoaches(this.setCoaches.bind(this));
}

// eslint-disable-next-line max-lines-per-function
setCoaches(answer) {
const coaches = answer.split(',');
coaches.forEach((coach) => {
this.#coaches.push(new Coach(coach));
});
console.log(this.#coaches.length);
readBannedFoods(
this.setCoachesBannedFoods.bind(this),
this.#coaches.map((c) => c.getName()),
0,
[],
);
// console.log(`bannedFoods are ${JSON.stringify(bannedFoods)}`);
}

setCoachesBannedFoods(arr) {
console.log(JSON.stringify(arr));
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/models/Coach.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const { readBannedFoods } = require('../views/InputView');

class Coach {
#name;

#bannedFoods = [];

constructor(name) {
// console.log(`${name} 코치 생성!`);
this.#name = name;
Expand All @@ -9,5 +13,16 @@ class Coach {
getName() {
return this.#name;
}

makeBannedFoods() {
return new Promise((resolve) => {
resolve(readBannedFoods(this.#name, this.setBannedFoods.bind(this)));
});
}

setBannedFoods(food) {
this.#bannedFoods.push(food);
console.log(`${this.#name}push 완료`);
}
}
module.exports = { Coach };
16 changes: 16 additions & 0 deletions src/views/InputView.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ const InputView = {
}
});
},

readBannedFoods(setCoachesBannedFoods, arr, index, result) {
console.log(arr.length, index, result);
if (index !== arr.length) {
const temp = [...result];
MissionUtils.Console.readLine(`${arr[index]}(이)가 못 먹는 메뉴를 입력해 주세요.\n`, (answer) => {
console.log(answer);
InputView.readBannedFoods(setCoachesBannedFoods, arr, index + 1, temp.concat({
name: arr[index],
foods: answer,
}));
});
} else {
setCoachesBannedFoods(result);
}
},
};

module.exports = InputView;

0 comments on commit c6dad71

Please sign in to comment.