Skip to content
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
32acb5d
스켈레톤 코드 작성
HTMLhead Oct 1, 2018
1feed23
수많은 에러가 담긴 todo객체의 add함수 추가(id의 값을 제대로 가지지 못함, todo객체의 getStatusNum수정 필요
HTMLhead Oct 1, 2018
2e1cca2
랜덤한 id값을 못가져오는 것을 수정. checkOverlap함수를 통해서 id의 값이 같지않도록 구현
HTMLhead Oct 1, 2018
a030244
todo.add함수기능 완벽하게 구현
HTMLhead Oct 1, 2018
705defd
todo.update함수 완성
HTMLhead Oct 1, 2018
7febf2e
id를 입력받아 할일을 제거해주는 todo.remove함수 완성, 오류가많은 todo.printTask함수 완성
HTMLhead Oct 1, 2018
364c939
todo.printTask함수 완성, tag를 확인하는 함수 제거(printTask를 통해 각 할일들의 태그가 무엇인지 확인…
HTMLhead Oct 1, 2018
6169d44
todo.printTagRelate 함수 완성, todo.add함수에서 버그를 발견함
HTMLhead Oct 1, 2018
2816a08
새로운 객체 안 배열에 저장하도록 만들어 문제 해결
HTMLhead Oct 2, 2018
2b5e634
remove함수를 호출했을때, saveData.task배열에서 지워지는것 뿐 아니라 saveData.idArrays배열에서도…
HTMLhead Oct 2, 2018
1619676
테스트코드를 주석처리함 들여쓰기를 다시 맞춤
HTMLhead Oct 2, 2018
154a4ca
saveData객체를 없애고 그 내용을 todo객체 안으로 집어 넣음, todo.idArrays의 값은 todo.add를 호…
HTMLhead Oct 2, 2018
2d2e47e
if(saveData.idArrays.indexOf(ranNum) !== -1)-> if(this.idArrays.inclu…
HTMLhead Oct 2, 2018
27328f4
기나긴 삼항연산자 statusNum[obj.status]++로 해결
HTMLhead Oct 2, 2018
33fd0ee
todo.update함수에서 바뀐 상태의 상태를 반영하지 않는 버그를 찾아내서 수정
HTMLhead Oct 2, 2018
0edc61f
함수마다 간단한 주석을 달아줌
HTMLhead Oct 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const todo = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스켈레톤 코드 잘했어요~

task: [],
idArrays: [],
Copy link
Contributor

Choose a reason for hiding this comment

The 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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

바로위에서 console.log 를 호출해서 무언가 출력하고,
그 다음줄에서는 console.log로 동작하는 함수를 호출하고,
비슷한 것들이니 같이 print함수쪽으로 모아서 처리하도록 하는 것도 검토할 수 있을 듯.

},//해야할일과 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 => {
Copy link
Contributor

Choose a reason for hiding this comment

The 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: '회사' })