Setup
It has officially been decided that numbers that end with zeroes are boring. They might be fun in your world, but definitely not here. Implement a function to eradicate any trailing zeroes. If the given number is 0, just leave him alone. Poor guy anyway.
Examples
1450 -> 145
960000 -> 96
1050 -> 105
-1050 -> -105
Tests
9070
210000
10210
0
This challenge comes from thecodix on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (25)
Recursive Haskell solution
Does this work when passing
0
as argument?Good catch, guess I missed that case. Updated it.
I find it interesting that every solution here uses strings, here's one acting on the numbers itself. (tested against the above and other values).
Javascript
I just realized the function returns undefined when it's not 0 so let me try to fix that real quick lol
codepen
Can someone tell my why the recursion I tried to do didn't work?
I guess you just need to add a 'return' in front of
The code will be--
Yep, that does it. Thanks!
Elixir
Elixir with recursion:
Elixir without recursion, inspired by @avalander 's solution:
Haskell
And the output:
C++
Python one liner
C#
and Dart
Felt like a bit of recursion is always fun to do.
And I couldn't remember when I used extensions in C# last...
Project on GitHub
A Dart solution using TDD :
Elm