File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 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"
You can’t perform that action at this time.
0 commit comments