Skip to content

Conversation

@HTMLhead
Copy link

@HTMLhead HTMLhead commented Oct 2, 2018

saveData라는 객체에 할일들의 배열과 id들의 배열을 저장해서 계속해서 사용하는 구조로 만들어 보았습니다.

  1. todo객체의 getRanNum함수로 랜덤한 숫자id를 만들어 냅니다. 만약 같은 id가 만들어진다면 다시한번 랜덤한 숫자를 생성되게 만들었습니다. todo.add함수에 이용됩니다.
  2. 지우거나 만들때마다 getStatusNum함수를 사용해서 todo와doing, done의 상태를 최신화 해주었습니다.
  3. printTask함수는 입력된 모든 할 일 들을 출력해줍니다.
  4. printSameTag는 tag를 입력받아 그 tag를 가진 할 일 들을 출력해줍니다.
  • '특히' 노력한점
  1. 중복되는 id값을 없애기 위해서 고민하고 또 고민했습니다.
  • 궁금한점
  1. saveData객체를 새로 만들어서 사용했는데, 이게 좋은방법인지 나쁜방법인지 궁금합니다.

@HTMLhead HTMLhead closed this Oct 2, 2018
@HTMLhead HTMLhead changed the base branch from master to HTMLhead October 2, 2018 06:39
@HTMLhead HTMLhead reopened this Oct 2, 2018
Copy link
Contributor

@crongro crongro left a comment

Choose a reason for hiding this comment

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

수고하셨어요~

메서드 단위가 작은규모라 좋군요.

saveData를 옮기셔야할거 같고, 그밖에 리뷰는 남기니 수정해보세요~

@@ -0,0 +1,27 @@
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.

스켈레톤 코드 잘했어요~

todo.js Outdated
@@ -0,0 +1,102 @@
const saveData = {
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에 각각 있는 id값과 idArrays가 완전히 정확히 동기화되어야 하는 어려움이 좀 있겠네요.
잘 맞출 수만 있다면 괜찮은 방법인거 같고요.
느리지만 정확하게 하려면 idArrays를 필요할때마다 task에서 추출하는 것이죠.

todo.js Outdated
const todo = {
getRanNum: function () {
const ranNum = Math.floor(Math.random() * 100)
if(saveData.idArrays.indexOf(ranNum) !== -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

중복방지로직은 좋아요~
array 에 include와 같은 메서드는 없는지도 한번 찾아보세요~

todo.js Outdated
done: 0
}
accumulatedTask.forEach(obj => {
obj['status'] === 'todo' ? statusNum.todo++ :
Copy link
Contributor

Choose a reason for hiding this comment

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

이건 어때요?

statusNum[obj.status]++

Copy link
Author

Choose a reason for hiding this comment

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

대단하네요.....진짜 감탄했습니다.

},

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.

새로운 객체 생성 잘했어요.

todo.js Outdated
@@ -0,0 +1,102 @@
const saveData = {
Copy link
Contributor

Choose a reason for hiding this comment

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

객체는
속성과 그속성을 제어하는 행위(함수)로 구성됩니다.

todo객체에서 task는 아주 중요한 속성이죠.
따라서 별로 객체에 두지않고 당연히 todo객체안에 있고, this를 통해서 객체안의 속성을 접근해야 합니다.

지금처럼 분리하는 경우는 todo와 같은 것이 한개 이상이고, 여러객체에서 saveData를 공유하는 경우에 그렇게 할수 있습니다.

Copy link
Author

Choose a reason for hiding this comment

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

친절하신 피드백과 답변 감사드립니다. 항상 크롱의 피드백은 여러번 읽으면 더 잘 이해되서 좋더라구요ㅎㅎ 감사합니다 바로 수정해서 다시 푸시하고 수정사항 달겠습니다.

@HTMLhead
Copy link
Author

HTMLhead commented Oct 2, 2018

  • 피드백 해주신대로 수정해보았습니다.
  1. todo객체와 밀접한 관련이 있는 saveData객체 내의 값을 모두 todo객체 안으로 옮겼습니다. todo.idArray의 값은 todo.add를 호출하면 추가되고, todo.remove를 호출하면 제거됩니다.
  2. 알려주신 방법대로 삼항연산자를 간단하게 수정하였습니다.
  3. todo.update를 호출 했을 때, 무조건 'todo => {바뀐 상태}' 로 출력되던것을 '{바뀌기 전상태} => {바뀐상태}' 로 출력되도록 수정하였습니다.

언제나 피드백 감사드립니다.

Copy link
Contributor

@crongro crongro left a comment

Choose a reason for hiding this comment

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

고민스러운 리뷰를 계속 남기게 되네요.
다음스텝 넘어가면서 고민(?) 이어가면서 해보세요.

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함수쪽으로 모아서 처리하도록 하는 것도 검토할 수 있을 듯.

}
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의 활용법을 잘 이해한거 같네요.
그런데 이렇게 구현하다보면 가끔 중복적인 반복은 아닌가? 싶은 마음도 들긴해요.
어려운 문제에요. 앞으로 다른것도 구현하면서 적절함을 찾아나가도록 해보세요.

@@ -0,0 +1,95 @@
const todo = {
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가 잘 맞는것이라는 확신!을 할 수 있을지..
소프트웨어는 보통 같은 데이터를 이렇게 동기화하진 않아요.
두 개의 참조가 다르기때문에 어떤이유로 달라질 수 있는 셈이죠.

@crongro crongro merged commit c9367fe into code-squad:HTMLhead Oct 3, 2018
crongro pushed a commit that referenced this pull request Oct 10, 2018
* Lecture3 - step1. 기본기능 구현 (#40)

* 스켈레톤 코드 작성

* 수많은 에러가 담긴 todo객체의 add함수 추가(id의 값을 제대로 가지지 못함, todo객체의 getStatusNum수정 필요

* 랜덤한 id값을 못가져오는 것을 수정. checkOverlap함수를 통해서 id의 값이 같지않도록 구현

* todo.add함수기능 완벽하게 구현

* todo.update함수 완성

* id를 입력받아 할일을 제거해주는 todo.remove함수 완성, 오류가많은 todo.printTask함수 완성

* todo.printTask함수 완성, tag를 확인하는 함수 제거(printTask를 통해 각 할일들의 태그가 무엇인지 확인이 가능하므로)

* todo.printTagRelate 함수 완성, todo.add함수에서 버그를 발견함

* 새로운 객체 안 배열에 저장하도록 만들어 문제 해결

* remove함수를 호출했을때, saveData.task배열에서 지워지는것 뿐 아니라 saveData.idArrays배열에서도 id를 지워지게 수정

* 테스트코드를 주석처리함 들여쓰기를 다시 맞춤

* saveData객체를 없애고 그 내용을 todo객체 안으로 집어 넣음, todo.idArrays의 값은 todo.add를 호출할때마다 추가되도록 수정.

* if(saveData.idArrays.indexOf(ranNum) !== -1)-> if(this.idArrays.includes(ranNum))으로 변경

* 기나긴 삼항연산자 statusNum[obj.status]++로 해결

* todo.update함수에서 바뀐 상태의 상태를 반영하지 않는 버그를 찾아내서 수정

* 함수마다 간단한 주석을 달아줌

* 주석추가

* 피드백을 위한 주석 추가

* 같은 숫자를 반복하는 것을 todo.task로부터 찾아와 sync가 완벽하게 맞도록 수정

* 쓸데없는 todo.idArrays에 쓰이는 배열과 메서드 제거

* 변수명 변경

* add나revmoe, update함수를 입력할때마다 각각 인자를 다르게 받아 다르게 출력하는 함수를 만듬

* 해야할 일들 주석으로 정리

* 만들어야 할 함수들 미리 작성

* time obj를 saveTimeObj로 이름을 변경하고 saveTimeObj에 doing일때의 시간과 done일때의 시간을 인자로 입력받아 경과된 시간을 반환해주는 getTakeTime 함수 구현

* 업데이트할 객체를 인자로 받아 id값과업데이트 될때의 시간 값을 saveTImeObj의 객체에 저장해주는 함수 구현

* todo.add함수에서 새 객체를 만들때 걸린시간 이라는 항목을 추가함

*  timeobj객체를 todo안으로 집어넣어 활용하기로 결정, 수정

* doingTimeArray와 takenTimeArray가 굳이 필요할것 같이 않아서 제거, 대신 task배열내의 객체에 timeData추가. 이를 이용해 updateDoingTime메서드 완성

* updateTakeTime메서드 구현. id가 같은 task.timeData값에 걸린 시간을 계산해서 저장해줌

* showTag메서드와 그 메서드를 위한 printByTag메서드 구현. printByTag는 tag과 status를 인자로 받아 같은인자와 tag를 출력, showTag메서드는 그 값을 세번 불러서 서로다른 3가지의 status값을 모두 출력.

* show메서드 구현 만약 status가 done상태일때만 시간을 출력해주도록 함

* printByTag메서드의 버그 수정(상태가done인 항목을 입력해도 걸린 시간이 나오지 않았음), show메서드의 버그 수정(상태가done이면 doing항목을 출력하라고 입력했을때 done항목도 같이 출력되었었음)

* 테스트 케이스 추가

* showAll메서드 구현, bind메서드를 이용함

* 같은태그를가짐과동시에 같은상태인것의 개수를 세는 함수 getSameTagAndStatusNum함수를 만듦

* show함수를 좀더 보기좋게 수정

* showTags를 위한 getSameTagArrays와 printSameTag함수를 만듬. 태그의 모든값이 담긴 배열을 만들고, 배열의 값을 통해 같은 값을 출력하는 함수를 만듬

* 태그가 같은 할 일의 개수를 계산해주는 함수 getSameTagNum을 만듬

* 함수의 쓰임새에 따라 정렬하여 보기편하게 수정

* 테스트 케이스들을 모두 주석처리하고 id의 경우의 수를 100가지로 늘림

* 사소한 버그 수정
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants