I've got 2 arrays: numberOfwords that has 100 numbers, and wordsArray that has 100 words. numberOfwords and wordsArray must be sorted together.
I'm trying to sort the words in wordsArray according to their lengths. When I call the function below, I get: wordsArray[b] is undefined.
My code:
CODE
function sortPhraseLength()
{
for(i = 0; i < 100; i++)
{
for(b = 0; b < 100; b++)
{
if(wordsArray[b].length < wordsArray[i].length) //the error is here - wordsArray[b] is undefined
{
temp = numberOfwords[b];
numberOfwords[b] = numberOfwords[i];
numberOfwords[i] = temp;
tempString = listOfWords[b];
wordsArray[b] = wordsArray[i];
wordsArray[i] = tempString;
}
}
}
return null;
}
{
for(i = 0; i < 100; i++)
{
for(b = 0; b < 100; b++)
{
if(wordsArray[b].length < wordsArray[i].length) //the error is here - wordsArray[b] is undefined
{
temp = numberOfwords[b];
numberOfwords[b] = numberOfwords[i];
numberOfwords[i] = temp;
tempString = listOfWords[b];
wordsArray[b] = wordsArray[i];
wordsArray[i] = tempString;
}
}
}
return null;
}
What am I doing wrong?
Any help will be appreciated.
Thanks