我提供的这组代码应使用我输入的任意数字并将其取反。当前,该函数在n = 21.365或n = 5698时起作用,但是当n = 0456456456时,它返回41422397而不是6546546540,或者在n = 056985时,它返回58965而不是589650,而在n = 016540时,它返回257而不是45610。
这是我到目前为止写的
//rules & limitations
//negative numbers should remain negative
//leading zeros should be removed
//the function can accept floats or integers
//the function will return integers as integers
function reverseNumberWithBuiltInFunctions(n) {
return (
parseFloat (
n
//convert the number to a string
.toString()
//convert to array of characters
.split('')
//reverse array of characters
.reverse()
//join reversed array of characters
.join('')
) * Math.sign(n)
)
}
Run Code Online (Sandbox Code Playgroud)
我想如果n = 001,则返回100;或者,如果n = …