Skip to content

Commit 2d07c50

Browse files
author
Neelesh Shetty
committed
Easy
1 parent 15264de commit 2d07c50

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

28.RemoveZeros.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Remove Trailing and Leading Zeros
2+
3+
// Create a function that takes in a number as a string n and returns the number without trailing and leading zeros.
4+
5+
// Trailing Zeros are the zeros after a decimal point which don't affect the value (e.g. the last three zeros in 3.4000 and 3.04000).
6+
// Leading Zeros are the zeros before a whole number which don't affect the value (e.g. the first three zeros in 000234 and 000230).
7+
8+
// ****Looking for a better approach & explanation
9+
10+
function removeLeadingTrailing(n) {
11+
return Number(n).toString()
12+
}
13+
14+
console.log(removeLeadingTrailing("230.000")) // "230"
15+
console.log(removeLeadingTrailing("00402")) // "402"
16+
console.log(removeLeadingTrailing("03.1400")) // "3.14"
17+
console.log(removeLeadingTrailing("30")) // "30"

0 commit comments

Comments
 (0)