Most valuable character

This commit is contained in:
2019-11-20 23:18:12 +01:00
parent 7c4d2234f2
commit 548eb2af09

View File

@@ -0,0 +1,11 @@
// https://www.codewars.com/kata/most-valuable-character/javascript
function solve(st) {
return [...new Set([...st])].map(c => {
return [c, st.lastIndexOf(c) - st.indexOf(c)];
}).sort((a, b) => {
const c = b[1] - a[1];
if (c === 0) return a[0].localeCompare(b[0]);
return c;
})[0][0];
}