Skip to content

Latest commit

 

History

History
12 lines (11 loc) · 304 Bytes

divisorArray.md

File metadata and controls

12 lines (11 loc) · 304 Bytes
func divisorArray(_ n : Int) -> [Int] {
    var array = [Int]()
    let sqrtValue = Int(sqrt(Double(n)))
    for i in 1...sqrtValue {
        if n % i == 0 { array.append(i); array.append(n/i) }
    }
    if sqrtValue * sqrtValue == n { array.removeLast() }
    
    return array.sorted()
}