-
Notifications
You must be signed in to change notification settings - Fork 41
Lecture3 - step1. 기본기능 구현 #40
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
Changes from all commits
32acb5d
1feed23
2e1cca2
a030244
705defd
7febf2e
364c939
6169d44
2816a08
2b5e634
1619676
154a4ca
2d2e47e
27328f4
33fd0ee
0edc61f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| const todo = { | ||
| task: [], | ||
| idArrays: [], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. task의 아이디와 idArrays가 sync가 잘 맞는것이라는 확신!을 할 수 있을지.. |
||
| getRanNum: function () { | ||
| const ranNum = Math.floor(Math.random() * 5) | ||
| if (this.idArrays.includes(ranNum)) { | ||
| return this.getRanNum(); | ||
| } | ||
| return ranNum; | ||
| },//중복되지 않는 랜덤한 숫자를뽑아내는 함수 | ||
|
|
||
| getStatusNum: function (accumulatedTask) { | ||
| const statusNum = { | ||
| todo: 0, | ||
| doing: 0, | ||
| done: 0 | ||
| } | ||
| accumulatedTask.forEach(obj => { | ||
| statusNum[obj.status]++ | ||
| }) | ||
| return statusNum | ||
| },//상태를 초기화 시켜주는 함수 | ||
|
|
||
| printStatusNum: function (statusNum) { | ||
| console.log(`현재상태 todo : ${statusNum.todo}, doing: ${statusNum.doing}, done : ${statusNum.done}`) | ||
| },//상태를 출력해주는 함수 | ||
|
|
||
| add: function (objToAdd) { | ||
| const newTodo = { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 새로운 객체 생성 잘했어요. |
||
| id: this.getRanNum(), | ||
| name: objToAdd.name, | ||
| status: 'todo', | ||
| tag: objToAdd.tag | ||
| } | ||
| this.idArrays.push(newTodo.id) | ||
| this.task.push(newTodo) | ||
| let statusNum = this.getStatusNum(this.task) | ||
| console.log(`ID : ${newTodo.id}, ${newTodo.name} 항목이 추가되었습니다.`); | ||
| this.printStatusNum(statusNum) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 바로위에서 console.log 를 호출해서 무언가 출력하고, |
||
| },//해야할일과 id값을 추가해주는 함수 | ||
|
|
||
| update: function (objToUpdate) { | ||
| let beforeTaskStatus = [] | ||
| this.task = this.task.map(taskObj => { | ||
| if (objToUpdate.id === taskObj.id) { | ||
| beforeTaskStatus.push(taskObj.status) | ||
| taskObj.status = objToUpdate.nextstatus.toLowerCase(); | ||
| return taskObj | ||
| } | ||
| return taskObj | ||
| }) | ||
| const changedTask = this.task.filter(taskObj => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. map, filter의 활용법을 잘 이해한거 같네요. |
||
| if (objToUpdate.id === taskObj.id) { | ||
| return taskObj | ||
| } | ||
| }) | ||
| let statusNum = this.getStatusNum(this.task) | ||
| console.log(`ID: ${changedTask[0].id}, ${changedTask[0].name} 항목이 ${beforeTaskStatus[0]} => ${changedTask[0].status} 상태로 업데이트 되었습니다.`) | ||
| this.printStatusNum(statusNum) | ||
| },//상태 업데이트 함수 | ||
|
|
||
| remove: function (objToRemove) { | ||
| let extractedTask = this.task.filter(taskObj => taskObj.id === objToRemove.id) | ||
| let deletedArrays = this.idArrays.filter(value => objToRemove.id !== value) | ||
| this.idArrays = deletedArrays | ||
| let removedTask = this.task.filter(taskObj => taskObj.id !== objToRemove.id) | ||
| this.task = removedTask | ||
| console.log(`ID : ${extractedTask[0].id}, ${extractedTask[0].name} 삭제 완료`) | ||
| },//할 일과 id값을 제거해주는 함수 | ||
|
|
||
| printTask: function () { | ||
| console.log(`입력된 할 일들`) | ||
| this.task.forEach(obj => { | ||
| console.log(`ID : ${obj.id}, 이름 : ${obj.name}, 상태 : ${obj.status}, 태그 : ${obj.tag}`) | ||
| }) | ||
| },//입력된 데이터들을 출력해주는 함수 | ||
|
|
||
| printSameTag: function (tag) { | ||
| console.log(`현재 ${tag} 태그를 가진 할 일들은 다음과 같습니다.`); | ||
| const tagSeparatedTask = this.task.filter(obj => { | ||
| return obj.tag === tag | ||
| }) | ||
| tagSeparatedTask.forEach(obj => { | ||
| console.log(`ID : ${obj.id}, 이름 : ${obj.name}, 상태 : ${obj.status}`) | ||
| }) | ||
| }//tag가 같은 할 일들 출력 | ||
| }//해야 할일 객체 | ||
|
|
||
| // 테스트 | ||
| todo.add({ name: '자바스크립트', tag: 'programming' }); | ||
| todo.add({ name: 'C++', tag: 'programming' }); | ||
| todo.add({ name: '회식', tag: '회사' }); | ||
| todo.add({ name: '노래연습', tag: '자기개발' }); | ||
| todo.add({ name: '과장님업무', tag: '회사' }) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
스켈레톤 코드 잘했어요~