text: Find the real and imaginary part of a Complex number | Function to find real and imaginary parts of a complex number ; string length stored in variable l ; variable for the index of the separator ; Storing the index of ' + ' ; else storing the index of ' - ' ; Finding the real part of the complex number ; Finding the imaginary part of the complex number ; Driver code
code: function findRealAndImag ( s ) { let l = s . length - 1 ; let i ; if ( s . indexOf ( ' ' ) != - 1 ) { i = s . indexOf ( ' ' ) ; } else { i = s . indexOf ( ' ' ) ; } let real = s . substr ( 0 , i ) ; let imaginary = s . substr ( i + 1 , l - 2 ) ; document . write ( " " + real + " " ) ; document . write ( " " + imaginary ) ; } let s = " " ; findRealAndImag ( s ) ;