--

The write function needs some modifications. Otherwise, it was a fine implementation.

```

write(key, value){

if(!this.head){

this.head = this.tail = new Node(key, value);

}else{

const node = new Node(key, value, this.head);

this.head.prev = node;

this.head = node;

}

//Update the cache map

if(this.cache[key]){

this.remove(key);

this.cache[key] = this.head;

this.size++;

}else{

this.ensureLimit();

this.cache[key] = this.head;

this.size++;

}

}

```

--

--

Sidhartha Mallick
Sidhartha Mallick

Written by Sidhartha Mallick

building investorsync.in/, iOS@Gojek, Ex- Intern@BrowserStack

No responses yet