Most valuable character
This commit is contained in:
11
most-valuable-character/index.js
Normal file
11
most-valuable-character/index.js
Normal 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];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user