728x90
// HashTable Challenge : add set, get methods class HashTable { constructor(size){ // set memory size this.data = new Array(size); // [['grapes', 10000]] } // hash function _hash(key) { let hash = 0; for (let i = 0; i < key.length; i++) { hash = (hash + key.charCodeAt(i) * i) % this.data.length } return hash; } } const myHashTable = new HashTable(50); myHashTable.set('grapes', 10000); myHashTable.get('grapes'); |
Private property
_hash? it is a kind of meaning-less property such as ‘You better not use this’ to other developers.
참고할 것들
https://javascript.info/private-protected-properties-methods
https://stackoverflow.com/questions/22156326/private-properties-in-javascript-es6-classes
728x90
'Research > Javascript' 카테고리의 다른 글
Javascript_for, for in, for of는 무엇이 다른가(번역) (0) | 2023.02.06 |
---|---|
forEach()는 Return으로 말릴 수 없는 짱구 (0) | 2022.11.28 |
Classes in JavaScript (0) | 2022.11.24 |
jquery_ready() 메소드로 페이지 로딩 즉시 함수 실행시키기 (0) | 2022.11.21 |
Javascript_Conditionals (0) | 2022.03.20 |
댓글