const solution = (cacheSize, cities) => {
const cache = [];
let count = 0;
if (cacheSize == 0) {
return cities.length * 5;
}
for (let i = 0; i < cities.length; i++) {
const current = cities[i].toLowerCase();
const indexForSplice = cache.indexOf(current);
if (indexForSplice != -1) {
count++;
cache.splice(indexForSplice, 1);
} else {
count += 5;
if (cache.length == cacheSize) {
cache.shift();
}
}
cache.push(current);
}
return count;
};