• + 4 comments

    I made this work in Swift by overloading the operator

    var n = Int(readLine()!)!
    
    func *(string: String, scalar:Int) -> String {
        let value = Array(count: scalar, repeatedValue: string)
        return value.joinWithSeparator("")
    }
    
    for i in 1..<n + 1 {
        print(" " * (n - i) + "#" * i)
    }
    

    https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AdvancedOperators.html