function lonliest(str) { str = str.trim(); let spaces = new Map(); let curLetter = str[0]; let spaceCount = 0; let biggestCount = 0; for(c of str) { if(c == ' ') { spaceCount++; } else { let sc = (spaces.has(curLetter)?spaces.get(curLetter):0)+spaceCount; spaces.set(curLetter, sc); if(sc > biggestCount) { biggestCount = sc; } curLetter = c; spaces.set(curLetter, spaceCount); spaceCount = 0; } } return [...spaces].filter(sc => sc[1] == biggestCount).map(sc => sc[0]); }
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.
Discussion on: Daily Challenge #297 - Loneliest Character
For further actions, you may consider blocking this person and/or reporting abuse