Skip to content

Instantly share code, notes, and snippets.

@DevGW
Created December 29, 2022 13:45
Show Gist options
  • Save DevGW/be7b22227e4f2b94b0b35abf1da95faa to your computer and use it in GitHub Desktop.
Save DevGW/be7b22227e4f2b94b0b35abf1da95faa to your computer and use it in GitHub Desktop.
Javascript :: toString and parseFloat
const zeroDarkThirty = (aNum) => {
const stringNum = aNum.toString();
let zerolessString = '';
for (let i = 0; i < stringNum.length; ++i) {
const currentDigit = stringNum[i];
if (currentDigit !== '0') zerolessString += currentDigit;
} return parseFloat(zerolessString);
}
// this takes a number and gets rid of the zeroes, and returns the zeroless number.
// parseFloat returns number with decimal places
// parseInt would return integer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment