Complex Number Class
Problem statement
Construct two integer complex numbers, add them, compare them for equality, and format them. Return [formattedSum, equality, formattedFirst, formattedSecond].
Formatting omits zero terms, writes coefficient 1 as i and -1 as -i, and uses a + bi or a - bi when both terms are nonzero.
Function
complexNumberSummary(firstReal: int, firstImaginary: int, secondReal: int, secondImaginary: int) → String[]Examples
Example 1
firstReal = 2firstImaginary = -1secondReal = -2secondImaginary = 1return = ["0","false","2 - i","-2 + i"]The numbers cancel under addition but are not equal.
Constraints
- All parts fit in signed 32-bit integers and their sums do too.