Your Submissions
You haven't submitted any code for this challenge yet. Solve the problem by passing all the test cases, and your submissions will appear here.
xxxxxxxxxx
31
var assert = require('assert');
class Cache {
constructor(capacity) {
// do something
}
}
try {
var cache = new Cache(3);
cache.put(1, 1);
cache.put(2, 4);
cache.put(3, 9);
assert.equal(cache.get(1), 1);
console.log(
'PASSED: Initialize a cache of size 3, and run `cache.put(1, 1); cache.put(2, 4); cache.put(3, 9);`. `cache.get(1)` should return 1'
);
} catch (err) {
console.log(err);
}
try {
cache.put(4, 16);
assert.equal(cache.get(2), -1);
console.log('PASSED: ' + '`cache.put(4, 16);` should evict key `2`');
OUTPUT
Results will appear here.