Last active
November 28, 2018 03:32
-
-
Save Risyandi/b0b723c3b2e41e2d9cbb267840f6b550 to your computer and use it in GitHub Desktop.
This is a assignment for Reverse 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
// Declare a global variable for the function reverse() | |
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"; | |
// function reverse with decrement | |
function Reverse(words) { | |
var wordsLength = words.length; | |
// console.log(wordsLength, "words length"); | |
var reverseWords = ""; | |
for (let index = wordsLength - 1; index >= 0; index--) { | |
reverseWords += words[index]; | |
// console.log(reverseWords, "words result reverse"); | |
} | |
return reverseWords; | |
} | |
// function tokenize | |
function Tokenize(words, delimeter) { | |
var indexj = 0, | |
wordsTokenize = [""]; | |
var wordsReverse = Reverse(words); | |
console.log("\x1b[34m" + "Process 1 Reverse: " + wordsReverse + " [words reverse]"); | |
var wordsReverseLength = wordsReverse.length; | |
var word = ""; | |
for (let index = wordsReverseLength - 1; index >= 0; index--) { | |
word += wordsReverse[index]; | |
if (wordsReverse[index] == delimeter) { | |
indexj++; | |
wordsTokenize[indexj] = ""; | |
} else { | |
wordsTokenize[indexj] += wordsReverse[index]; | |
} | |
} | |
console.log("\x1b[32m" + "Process 2 Normalization: " + word + " [words normal]"); | |
console.log(wordsTokenize); | |
return wordsTokenize; | |
} | |
// Call function tokenize() | |
Tokenize(words, " "); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment