I'm trying to create a program that condenses a string to how many characters it has. Just to give my non-programming friends an idea of how compression can work.
Unfortunately, I can't seem to put the same alphabets into a single arrays and other same sets of alphabets in other respective arrays.
The code is not complete, as I lost a lot of data from my HDD and this was all I had backed up on Google Drive. Can anyone please help me with this? Thanks!
var string = "twinkle twinkle little star how i wonder what you are up above the world so high like a diamond in the sky twinkle twinkle little star"
var brokenString = string.split("")
var counter = 0;
for (i = 1; i < brokenString.length; i++) {
while (brokenString[counter] === brokenString[i]) {
//var eval("array" + counter) = new Array(brokenString[i])
var array = {
counter: brokenString[i]
}
counter++
}
}
console.log(array)
new Array(brokenString)does what you think it does. It creates a new array with one element, and that element is thebrokenStringarray.stringand puts it into an array calledbrokenStringnew Array(brokenString)to anything. What's the purpose of that line?brokenStringis already an array, callingnew Array()doesn't do anything to it.var array? You're creating that object, but not doing anything with it.new Array(brokenString)is useless. And now I understand your second comment as well. Thank you for that!