I have a list of names that need to ordered by the name length, starting with the longest name. It is strange but it seems to have a few names that are not being picked up properly and I cannot see why.
Code: Select all
function sortByLength @pArray
local tSortedArray
local tNextIndex
get the keys of pArray
put the number of elements of pArray into tCount
sort lines of it descending by the length of pArray[each]
split it by return
put 1 into tNextIndex
repeat for each element tIndex in it
put pArray[tIndex] into tSortedArray[tNextIndex]
add 1 to tNextIndex
end repeat
return tSortedArray
end sortByLength
on openCard
put "Aaron,Abel,Abigail,Abraham,Enoch,Jeroboam,Benjamin,Dorcas,Isaac,Ishmael," &\
"Job,Joseph,Lazarus,Luke,Mark,Mary,Miriam,Moses,Noah,Reuben,Nehemiah," &\
"Jezebel,Jehovah,Jethro,Judas,Laban,Samuel,Saul,Solomon,Thomas,Timothy," &\
"Uriah,Zechariah,Potiphar,Mordecai,Rachel,Deborah,Cornelius,Belshazzar," &\
"Bathsheba,Andrew,Amos,Amnon,Adam,Achan,Nathan,Ezra,Rahab,Paul,Martha,Ahab," &\
"Levi,Jehu,Jonathan,Jonah,Rehoboam,Shem,Elijah,Caiaphas,Jacob,Ezekiel,Nimrod," &\
"Nebuchadnezzar,John,Balaam,Barnabas,Hezekiah,Lot,Gideon,Eli,David,Joshua," &\
"Melchizedek,Esther,Sarah,Zedekiah,Elisha,Nicodemus,Isaiah,Ruth,Zacchaeus," &\
"Rebekah,Samson,Nathanael,Matthew,Hagar,Josiah,Hiram,James,Absalom,Caleb," &\
"Ahasuerus,Pharaoh,Jephthah,Lamech,Philip,Cain,Gabriel,Hosea,Esau,Jesus,Peter," &\
"Eve,Daniel" into tNameList
put empty into tArray
put 1 into tCounter
set itemdel to comma
repeat for each item tWord in tNameList
put tWord into tArray[tCounter]
add 1 to tCounter
end repeat
put sortByLength(tArray) into tArraySorted
put empty into tList1
repeat for each element tWord in tArray
put tWord & CR after tList1
end repeat
put tList1 into field "Field1"
put empty into tList2
repeat for each element tWord in tArraySorted
put tWord & CR after tList2
end repeat
put tList2 into field "Field2"
end openCard