                     continue
                 }
             }
-
+            
             // Same case bonus.
-            if (string[idxOf] == word[word.characters.index(word.startIndex, offsetBy: i)]) {
+            if (string[idxOf] == word[word.index(word.startIndex, offsetBy: i)]) {
                 charScore += 0.1
             }
-
+            
             // Update scores and startAt position for next round of indexOf
             runningScore += charScore
             startAt = string.index(idxOf, offsetBy: 1)
         }
-
+        
         // Reduce penalty for longer strings.
         finalScore = 0.5 * (runningScore / Double(strLength) + runningScore / Double(wordLength)) / fuzzies
-
+        
         if (lWord[lWord.startIndex] == lString[lString.startIndex]) && (finalScore < 0.85) {
             finalScore += 0.15
         }
-
+        
         return finalScore
     }
 }

        fuzzies = 1.0,
        fuzzyFactor = 0.0,
        fuzzinessIsNil = true

        // Cache fuzzyFactor for speed increase
        if let fuzziness = fuzziness {
            fuzzyFactor = 1 - fuzziness
            fuzzinessIsNil = false
        }

        for i in 0 ..< wordLength {
            // Find next first case-insensitive match of word's i-th character.
            // The search in "string" begins at "startAt".
            if let range = lString.range(
            of: String(lWord[lWord.characters.index(lWord.startIndex, offsetBy: i)] as Character),
            options: NSString.CompareOptions.caseInsensitive,
            range: Range<String.Index>(startAt..<lString.endIndex),
            locale: nil
            ) {
                // start index of word's i-th character in string.
                idxOf = range.lowerBound
                if startAt == idxOf {


public extension String
{
    func score(word: String, fuzziness: Double? = nil) -> Double
    {
        // If the string is equal to the word, perfect match.
        if self == word {
            return 1
        }
        
        //if it's not a perfect match and is empty return 0
        if word.isEmpty || self.isEmpty {
            return 0
        }
        
        var
        runningScore = 0.0,
        charScore = 0.0,
