Created
January 11, 2025 07:20
-
-
Save mary-ext/71c718112ca9c4f9e08b3940ff5d34dc 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 split = (str: string, delimiter: string, limit: number): string[] => { | |
const result: string[] = []; | |
let last = 0; | |
while (--limit > 0) { | |
const index = str.indexOf(delimiter, last); | |
if (index === -1) { | |
break; | |
} | |
result.push(str.slice(last, index)); | |
last = index + delimiter.length; | |
} | |
result.push(str.slice(last)); | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment