Skip to content

Instantly share code, notes, and snippets.

@Akifcan
Created July 10, 2022 08:26
Show Gist options
  • Save Akifcan/7edc5febcc705821a95be2755bbd61a9 to your computer and use it in GitHub Desktop.
Save Akifcan/7edc5febcc705821a95be2755bbd61a9 to your computer and use it in GitHub Desktop.
My own split implementation in javascript
const mySplit = (str, part) => {
const arr = []
let currentWorld = ''
for(let i = 0; i<str.length; i++){
const current = str[i]
if(current !== part){
currentWorld+=current
}
if(current === part || str.length - 1 === i){
arr.push(currentWorld)
currentWorld = ''
}
}
return arr
}
console.log(mySplit('hello-world-demo', '-'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment