# Loop error in Text Compression (indexing words)

**URL:** <https://forum.kirupa.com/t/loop-error-in-text-compression-indexing-words/208169>\
**Category:** Uncategorized\
**Created:** [November 25, 2006, 10:50pm UTC](https://forum.kirupa.com/t/loop-error-in-text-compression-indexing-words/208169 "2006-11-25T22:50:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![superjohn](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@superjohn](https://forum.kirupa.com/u/superjohn)\
**Post date:** [November 25, 2006, 10:50pm UTC](https://forum.kirupa.com/t/loop-error-in-text-compression-indexing-words/208169/1 "2006-11-25T22:50:39Z")

</div>

Im trying to make a script that compresses a certain text, by replacing often used words with an index number. I also want to optimize it by looking at the number of times a certain word is used. The code below is just a starting point, trying to test if a word from the text\_array is in the (final) Index Array. If not i should be added, if it is already in there the count should go up with 1. Sounds simple ey? well i managed to screw it up… I get way to much entries in my Index, so i must be overlooking something… any help?

```auto

text1="test1 test2 test3 test1 test1 test3 test1 test2";

tempArray=text1.split(" ");

var Index = new Array();
Index = [["word",1]]

for (i=0;i<tempArray.length;i++){g=1;
    for (j=0;j<Index.length;j++){
        if (tempArray*!=Index[j][0]) {
            Index.push([tempArray*,[g]]);                      
}
else{g++;Index[j][1]=g;}

    }}
trace(Index.length);

```
