Home >Web Front-end >JS Tutorial >TIL: How to Trim Trailing Zeros【CodeWars】
No zeros for heros
This question requires removing trailing zeros from a number while preserving its integrity.
1450 -> 145 960000 -> 96 1050 -> 105 -1050 -> -105
8kyu (easiest level on Codewars)
function noBoringZeros(n) { while (n % 10 === 0 && n !== 0) { n = n / 10 } return n }
const noBoringZeros = n => n % 10 === 0 && n !== 0 ? noBoringZeros(n / 10) : n;
function noBoringZeros(n) { return +`${n}`.replace(/0*$/, ""); }
[][(![]+[])[+!![]]+(!![]+[])[+[]]][([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[+!![]+[+[]]]+([][[]]+[])[+!![]]+(![]+[])[! ![]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+[][(![]+[])[+!![]]+(!![]+[])[+[]]])[!![]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+!![]]+(!![]+[])[+[]]] )[+!![]+[+[]]]+(!![]+[])[+!![]]]((!![]+[
(here's an excerpt)
I prefer "Solution 3" because it's simple and reader-friendly while still demonstrating some useful techniques.
If you're curious about these solutions or want to explore more challenges, visit here.
Thank you for reading! ?
The above is the detailed content of TIL: How to Trim Trailing Zeros【CodeWars】. For more information, please follow other related articles on the PHP Chinese website!