Created
August 31, 2020 09:17
-
-
Save NateScarlet/19a5b4d4b50768f127e98e041cdeb898 to your computer and use it in GitHub Desktop.
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
/** Split string to exact n parts, last part may contains splitter. */ | |
export default function splitN(v: string, splitter: string, n: number): string[] { | |
const parts = v.split(splitter); | |
const ret = parts.slice(0, n); | |
while (ret.length < n) { | |
ret.push(''); | |
} | |
ret[n - 1] = parts.slice(n - 1).join(splitter); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment