Skip to content

4주차 과제#4

Open
KJeeu wants to merge 5 commits intoCodeSoom:mainfrom
KJeeu:jiho
Open

4주차 과제#4
KJeeu wants to merge 5 commits intoCodeSoom:mainfrom
KJeeu:jiho

Conversation

@KJeeu
Copy link
Copy Markdown

@KJeeu KJeeu commented Dec 31, 2023

마지막 선형 탐지 해싱 테이블은 그림은 그렸는데 구현은 못했습니다ㅜ

이진탐색트리
IMG_1601

2-3트리
IMG_1602

레드블랙트리
IMG_1603

개별해시테이블, 선형해시테이블
IMG_1604

Comment on lines +51 to +54
if (this.get(key)) {
return true;
}
return false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

JavaScript에서 이런 경우 이렇게도 많이 씁니다.

return !!this.get(key);

변수 앞에 !를 붙이면 true -> false, false -> true로 바뀌잖아요. 이걸 2번 하면 true -> false -> true가 되겠죠. 어차피 아무것도 안하는데 왜 쓰냐고 할 수 있지만, 자바스크립트에는 Truthy와 Falsy가 있어요. 1, {}, [], 길이 1이상 문자열 등등은 true라고 가정하고, undefined, null, 0, "" 빈 문자열 등은 false라고 가정하죠.

그래서 어떤 객체가 주어졌을 때 !를 하나 붙이면 false가 되고 여기서 !를 하나 더 붙이면 true가 되므로 어떤 값이 있다는 것을 boolean변수로 변환할 수 있죠.

See also

Comment on lines +58 to +60
if (this.#n === 0) {
return true;
} return false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

return this.#n === 0;

이렇게 써도 되겠네요

}

keys() {
return this.#keys;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

각 속성들을 private으로 선언한 이유가 외부에서 함 부로 접근하고 수정하지 못하도록 한거예요. 여기서 this.#keys를 직접 반환하게 되면 외부에서 값을 조작할 수 있어서 위험할 수 있어요. 이럴 때는 복사해서 넘겨주는게 좋습니다. 그러면 복사한 값을 고쳐도 안에 있는 값에는 영향을 받지 않아요.

return [...this.#keys];

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