Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions javascript/2710-remove-trailing-zeros-from-a-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @param {string} num
* @return {string}
*/
var removeTrailingZeros = function (num) {

for (let i = num.length - 1; i >= 0; i--) { // loop through the every element of string num from end
if (num[i] != 0) { // if every character of num is not equal to zero
return num.slice(0, i + 1); // return the character of num upto ith character
}
}
};