Created
September 11, 2021 08:23
-
-
Save bylatt/e7d1ddfbf56fed68bbec806c6956ff66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const input = ["ab", "aabbcc", "ababab", "abaabcca"]; | |
const sol = (words) => | |
words.map( | |
(word) => | |
word.split("").reduce( | |
(prev, cur) => | |
prev.lastChar === cur | |
? { | |
...prev, | |
lastChar: "", | |
result: [...prev.result, `${prev.lastChar}${cur}`], | |
} | |
: { ...prev, lastChar: cur }, | |
{ | |
result: [], | |
lastChar: "", | |
} | |
).result.length | |
); | |
console.log(sol(input)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment