Skip to content

Instantly share code, notes, and snippets.

@Risyandi
Last active November 12, 2018 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Risyandi/c8bee964ab6fab888259a23b89a279a0 to your computer and use it in GitHub Desktop.
Save Risyandi/c8bee964ab6fab888259a23b89a279a0 to your computer and use it in GitHub Desktop.
This is a assignment for Tokenize String Program using javascript
// 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