param { string } s return { string [ ] } function RestoreipAddress ( s ) { if ( typeof s !== 'string' || s . length > 12 ) { return [ ] ; } let result = [ ] ; ipHandler ( s , [ ] , result ) ; return result ; } param { string } remain param { string [ ] } temp param { string [ ] } result function ipHandler ( remain , temp , result ) { if ( temp . length === 3 ) { regular ( remain ) && result . push ( [ ... temp , remain ] . join ( '.' ) ) ; return ; } for ( let i = 1 ; i < 4 ; i ++ ) { regular ( remain . substr ( 0 , i ) ) && ipHandler ( remain . substr ( i ) , [ ... temp , remain . substr ( 0 , i ) ] , result ) ; } } param { string } s return { boolean } function regular ( s ) { if ( ! s . length ) return false ; return + s >= 0 && + s <= 255 && ( s . length > 1 ? s . charAt ( 0 ) !== '0' : true ) ; } export { RestoreipAddress } ;