Last active
September 4, 2020 09:13
-
-
Save peterszerzo/96fe455f4634c7a492e52b7259e916d0 to your computer and use it in GitHub Desktop.
Remove consecutive empty lines from a piece of text
This file contains 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
import mapAccum from "ramda/src/mapAccum"; | |
const removeConsecutiveEmptyLines = (val: string): string => | |
mapAccum( | |
(previous: null | string, current: string) => { | |
return [current, previous === "" && current === "" ? null : current]; | |
}, | |
null, | |
val.split("\n") | |
)[1] | |
.filter((val: string | null) => val !== null) | |
.join("\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment