Skip to content

Instantly share code, notes, and snippets.

@peterszerzo
Last active September 4, 2020 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterszerzo/96fe455f4634c7a492e52b7259e916d0 to your computer and use it in GitHub Desktop.
Save peterszerzo/96fe455f4634c7a492e52b7259e916d0 to your computer and use it in GitHub Desktop.
Remove consecutive empty lines from a piece of text
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