Last active
November 12, 2018 10:07
-
-
Save Risyandi/c8bee964ab6fab888259a23b89a279a0 to your computer and use it in GitHub Desktop.
This is a assignment for Tokenize String Program using javascript
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
// Input words | |
var words = "Ketua DPP Partai Hanura Inas Nasrullah Zubir mengungkapkan, dalam mitos Jawa, genderuwo merupakan bangsa jin atau makhluk halus yang berwujud manusia. Genderuwo memiliki tubuh besar dan suka menghisap darah manusia"; | |
// ways 1 | |
// breaks words into tokenize with define spaces | |
var words_temp = [''], | |
indexj = 0; | |
function tokenize(words, delimeter) { | |
for (let index = 0; index < words.length; index++) { | |
// appear indexing | |
console.log(index, "index"); | |
if (words[index] == delimeter) { | |
// increment indexj | |
indexj++; | |
// appear num indexing num array | |
console.log(indexj, "num indexing array"); | |
// push delimeter space as empty to the words_temp[] | |
words_temp[indexj] = ""; | |
var input_empty = words_temp[indexj] = ""; | |
console.log(input_empty, "empty"); | |
} else { | |
// join words to the words_temp[] | |
words_temp[indexj] += words[index]; | |
// result can be ["val", "val", "val"] | |
result = words_temp; | |
} | |
} | |
} | |
tokenize(words, " "); | |
console.log(result); | |
// output words | |
// ["Ketua", "DPP", "Partai", "Hanura", "Inas", "Nasrullah", "Zubir", "mengungkapkan,", "dalam", "mitos", "Jawa,", "genderuwo", "merupakan", "bangsa", "jin", "atau", "makhluk", "halus", "yang", "berwujud", "manusia.", "Genderuwo", "memiliki", "tubuh", "besar", "dan", "suka", "menghisap", "darah", "manusia"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment