Given is the following:
var theArray: [String] = ["uncool", "chill", "nifty", "precooled", "dandy", "cool"]
I want to sort the array by how similar the words are to the key word.
var keyWord: String = "cool"
The wanted result would be:
print// ["cool", "uncool", "precooled", ...] and then it does not matter anymore. But the words that are the key or contain it should be the very first objects.
My closest tryout so far has been:
let _theArray = entries.sorted { element1, element2 in
return element1.contains(keyWord) && !element2.contains(keyWord)
}
But that results in uncool being the first item, then precooled and the most related item cool even comes after nifty .
What am I missing?