Skip to content

Commit da1866d

Browse files
committed
Fixed up the signum function
1 parent 817a7e0 commit da1866d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Maths/Signum.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212

1313
/**
1414
* @param {Number} input
15-
* @returns {-1 | 0 | 1 | NaN} sign of input (and NaN if the input is NaN)
15+
* @returns {-1 | 0 | 1 | NaN} sign of input (and NaN if the input is not a number)
1616
*/
1717
function signum (input) {
18-
if (isNaN(input)) return NaN
19-
else if (input === 0) return 0
18+
if (input === 0) return 0
19+
else if (input > 0) return 1
2020
else if (input < 0) return -1
21-
else return 1
21+
22+
return NaN
2223
}
2324

2425
export { signum }

0 commit comments

Comments
 (0)