3 ms·
This was my thought as well. So many people jump to complicated math when the question was about a function. KISS applies, as does out of the box thinking. :)
by Viper007Bond 13y ago
This was my thought as well. So many people jump to complicated math when the question was about a function. KISS applies, as does out of the box thinking. :)
And here's a solution (in PHP, my language of choice) that doesn't use any static variables :
function f( $n ) {
if ( is_string( $n ) ) {
return -1 * (int) $n;
} else {
return (string) $n;
}
}