I very new to Swift and programming in general, so I can't figure out where is the problem. Tried to find the answer in the existing topics - couldn't. Thanks in advance.
func smartAssigning(names: [String], statuses: [Bool], projects: [Int], tasks: [Int]) -> String {
    //beginig
    var collect: [Int] = [], nameLast = 0
    var candidateNumber: [Int] = []
    for x in 0...statuses.count {
        //Defines who is working
        if statuses[x] == false {
            collect.append(x)
        } else {}
    }
    // Checks for min tasks assigned among those not on vacation
    let rt: Int = tasks.min()!
    let rp: Int = projects.min()!
    for i in collect {
        if tasks[i] == rt {
            candidateNumber.append(i)
        } else {}
    }
    // if there is only 1 with min tasks - returns his number in array
    if candidateNumber.count == 1 {
        nameLast = candidateNumber[0]
    } else {
        // checks for min projects
        for e in candidateNumber {
            if projects[e] == rp {
                nameLast = e
            }
        }
    }
    return names[nameLast]
}
smartAssigning(names: ["sd", "dfsd","dfsdf"], statuses: [true, false, false], projects: [2, 1, 1], tasks: [3, 2, 1])
Screen:

 
                        
The error is here:
If
statuses.countisn, then the maximum index isn-1. It should be0..<statuses.count. You should avoid manually creating such a range, exactly because it can cause this typo. It's much better to just dofor x in status.indices.On a side note, you don't need to have an
elseclause if it doesn't do anything.Also, rather than comparing against false (
== false), just negate theBool.This whole code can be written using a single
filter(_:)expression: