Multiplication of two complex numbers given as strings | javascript program to multiply two complex numbers given as strings . ; Spiting the real and imaginary parts of the given complex strings based on ' + ' and ' i ' symbols . ; Storing the real part of complex string a ; Storing the imaginary part of complex string a ; Storing the real part of complex string b ; Storing the imaginary part of complex string b ; Returns the product . ; Driver function
function complexNumberMultiply ( a , b ) { var x = a . split ( ' ' ) ; var y = b . split ( ' ' ) ; var a_real = parseInt ( x [ 0 ] ) ; var a_img = parseInt ( x [ 1 ] ) ; var b_real = parseInt ( y [ 0 ] ) ; var b_img = parseInt ( y [ 1 ] ) ; return ( a_real * b_real - a_img * b_img ) + " " + ( a_real * b_img + a_img * b_real ) + " " ; } var str1 = " " ; var str2 = " " ; document . write ( complexNumberMultiply ( str1 , str2 ) ) ;