Created
May 28, 2017 23:35
-
-
Save ThadeusAjayi/1b87f9ed52822081cd199b952ce8ca29 to your computer and use it in GitHub Desktop.
Alternative function to str.split() in javascript where you have have the error "TypeError: sentence.split is not a function"
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
| function split(sentence){ | |
| var arrayPosition = 0; | |
| var oneWord = ""; | |
| var newSentence = sentence + " "; | |
| var split = new Array(); | |
| for(var j = 0; j < newSentence.length; j++){ | |
| if(newSentence[j] === " "){ | |
| split.push(oneWord); | |
| arrayPosition++; | |
| oneWord = ""; | |
| }else{ | |
| if(!isNaN(newSentence[j])){ | |
| //don't add to the string | |
| }else{ | |
| oneWord += newSentence[j]; | |
| } | |
| } | |
| } | |
| return split; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.