Last updated 4 years ago
Was this helpful?
split as character
sorting for comparison
compare through reduce
reduce
if accumulator char code + 1 is not same current char code return false;
if all test passed return last character
!!(last character) is true so the result will return boolean
const solve = (s) => !![...s].sort() .reduce((acc, cur, i, arr) => { if (acc.charCodeAt(0) + 1 !== cur.charCodeAt(0)) { arr.splice(0); return false; } return cur; });