Skip to content

Commit 4c65486

Browse files
committed
fix coding styles
1 parent afd23cb commit 4c65486

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/data-structures/custom/lru-cache.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11

22
/**
3-
* Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.
3+
* Design and implement a data structure for Least Recently Used (LRU) cache.
4+
* It should support the following operations: get and put.
45
5-
get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
6-
put(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.
6+
get(key) - Get the value (will always be positive) of the key
7+
if the key exists in the cache, otherwise return -1.
8+
put(key, value) - Set or insert the value if the key is not already present.
9+
When the cache reached its capacity, it should invalidate the least
10+
recently used item before inserting a new item.
711
812
Follow up:
913
Could you do both operations in O(1) time complexity?
@@ -27,7 +31,7 @@
2731
*
2832
* @param {number} capacity
2933
*/
30-
const LRUCache = function (capacity) {
34+
const LRUCache = (capacity) => {
3135
this.map = new Map();
3236
this.capacity = capacity;
3337
};
@@ -36,7 +40,7 @@ const LRUCache = function (capacity) {
3640
* @param {number} key
3741
* @return {number}
3842
*/
39-
LRUCache.prototype.get = function (key) {
43+
LRUCache.prototype.get = (key) => {
4044
const value = this.map.get(key);
4145
if (value) {
4246
this.moveToTop(key);
@@ -50,20 +54,20 @@ LRUCache.prototype.get = function (key) {
5054
* @param {number} value
5155
* @return {void}
5256
*/
53-
LRUCache.prototype.put = function (key, value) {
57+
LRUCache.prototype.put = (key, value) => {
5458
this.map.set(key, value);
5559
this.rotate(key);
5660
};
5761

58-
LRUCache.prototype.rotate = function (key) {
62+
LRUCache.prototype.rotate = (key) => {
5963
this.moveToTop(key);
6064
while (this.map.size > this.capacity) {
6165
const it = this.map.keys();
6266
this.map.delete(it.next().value);
6367
}
6468
};
6569

66-
LRUCache.prototype.moveToTop = function (key) {
70+
LRUCache.prototype.moveToTop = (key) => {
6771
if (this.map.has(key)) {
6872
const value = this.map.get(key);
6973
this.map.delete(key);

src/data-structures/maps/hash-maps/hashing.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable */
2+
13
// tag::naiveHashCode[]
24
/**
35
* Naïve implementation of a non-cryptographic hashing function

src/data-structures/trees/red-black-tree.spec.js

-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ describe('RedBlackTree', () => {
2727
});
2828

2929
it('should balance tree by rotating left', () => {
30-
// const n1 = tree.add(1);
31-
// const n2 = tree.add(2);
32-
// const n3 = tree.add(3);
33-
// console.log(n3)
34-
3530
expect(tree.size).toBe(3);
3631

3732
expect(tree.toArray()).toEqual([

0 commit comments

Comments
 (0)