Skip to content

Instantly share code, notes, and snippets.

View hawaijar's full-sized avatar
🎯
Focusing

Mayengbam Sushil K hawaijar

🎯
Focusing
View GitHub Profile
@hawaijar
hawaijar / lru.js
Created May 13, 2021 05:43
Simple LRU cache using only Array
const LRUCache = function (capacity) {
this.cache = [];
this.capacity = capacity;
this.count = 0;
};
LRUCache.prototype.get = function (key) {
const obj = this.cache.find((item) => item.key === key);
if (obj) {
this.cache = this.cache.filter((item) => item.key !== key);
this.cache.push(obj);
@hawaijar
hawaijar / minHeap.js
Created April 24, 2021 13:59
Implementing min-heap
class Heap {
constructor() {
this.container = [];
}
getLeftChildIndex(parentIndex) {
return 2 * parentIndex + 1;
}
getRightChildIndex(parentIndex) {
return 2 * parentIndex + 2;
}
const ROMAN_MAPPING = {
1: 'I',
5: 'V',
10: 'X',
50: 'L',
100: 'C',
500: 'D',
1000: 'M',
4: 'IV',
9: 'IX',