Skip to content

Instantly share code, notes, and snippets.

@mreed4
Created March 6, 2025 05:01
Show Gist options
  • Save mreed4/a7ece112e9e0db43864fd99a6d1aaee4 to your computer and use it in GitHub Desktop.
Save mreed4/a7ece112e9e0db43864fd99a6d1aaee4 to your computer and use it in GitHub Desktop.
// mreed4 committed on Aug 8, 2021
const addLeadingZeros = n => {
let desiredLength = 3;
if (n.length === 1) {
while (n.length < desiredLength) {
n = `0` + n;
}
}
console.log(n.toString());
}
const addCommas = n => {
let toNum = num => Number(num);
if (n > 3) {
arr = Array.from(String(n), toNum);
let commaArr = arr.splice(0, 1, ",");
console.log(n);
console.log(arr);
console.log(commaArr);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment