Last active
January 12, 2022 07:35
-
-
Save hperrin/8ffe2146e81da81facfd3be42dfbde0c to your computer and use it in GitHub Desktop.
Revisions
-
hperrin revised this gist
Jan 12, 2022 . 2 changed files with 14 additions and 11 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,7 @@ export default const splitn = (s, d, n = Infinity) => { const a = s.split(d); return [ ...a.slice(0, n - 1), ...(a.length >= n ? [a.slice(n - 1).join(d)] : []) ]; }; 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ export default const splitn = (s: string, d: string, n = Infinity) => { const a = s.split(d); return [ ...a.slice(0, n - 1), ...(a.length >= n ? [a.slice(n - 1).join(d)] : []) ]; }; -
hperrin revised this gist
Jan 12, 2022 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ export default const splitn = (s: string, d: string, n = Infinity) => s.split(d).reduce( (a: string[], c: string) => ((a.length === n ? (a[a.length - 1] = [a[a.length - 1], c].join(d)) : a.push(c)) && a) as unknown as string[], [] ); -
hperrin created this gist
Jan 12, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ export default const splitn = (s, d, n = Infinity) => s.split(d).reduce( (a, c) => (a.length === n ? a[a.length-1] = [a[a.length-1], c].join(d) : a.push(c)) && a, [] );