Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
24
Task/Arithmetic-Complex/Swift/arithmetic-complex-2.swift
Normal file
24
Task/Arithmetic-Complex/Swift/arithmetic-complex-2.swift
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
extension Complex : CustomStringConvertible {
|
||||
|
||||
public var description : String {
|
||||
|
||||
guard real != 0 || imaginary != 0 else { return "0" }
|
||||
|
||||
let rs : String = real != 0 ? "\(real)" : ""
|
||||
let iS : String
|
||||
let sign : String
|
||||
let iSpace = real != 0 ? " " : ""
|
||||
switch imaginary {
|
||||
case let i where i < 0:
|
||||
sign = "-"
|
||||
iS = i == -1 ? "i" : "\(-i)i"
|
||||
case let i where i > 0:
|
||||
sign = real != 0 ? "+" : ""
|
||||
iS = i == 1 ? "i" : "\(i)i"
|
||||
default:
|
||||
sign = ""
|
||||
iS = ""
|
||||
}
|
||||
return "\(rs)\(iSpace)\(sign)\(iSpace)\(iS)"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue