Driver code
let arr = [ " " , " " , " " , " " ] ; let n = arr . length ; let ans = commonPrefix ( arr , 0 , n - 1 ) ; if ( ans . length != 0 ) { document . write ( " " + ans ) ; } else { document . write ( " " ) ; }