Almost identical but I try with the functional approach and typescript checks any number of chars instead of one.
const getDiff = (a:number, b: number):number => b - a const getGap = (a:number, maxDiff:number = 1):number => a - maxDiff const fillGaps = (a:number, gap:number):string[] => gap > 0 ? [...(Array(gap).fill(0))].map((_, e) => e + 1 ) .map(i => i + a ) .map(i => String.fromCharCode(i)) : [] const missing = (input:string[]): string => { return input.reduce((a, b, index, array) => { const positionIndex = `${b}`.charCodeAt(0) const nextPositionIndex:number = index + 1 < array.length ? array[index+1].charCodeAt(0) : positionIndex const gap = getGap(getDiff(positionIndex, nextPositionIndex), 1) const gaps = fillGaps(positionIndex, gap) return [...a,...gaps] }, []).join(', ') }
codesandbox.io/s/quirky-davinci-sk826
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Almost identical but I try with the functional approach and typescript
checks any number of chars instead of one.
codesandbox.io/s/quirky-davinci-sk826