Skip to content

Instantly share code, notes, and snippets.

@rozanovz
Created February 26, 2024 14:01
Show Gist options
  • Select an option

  • Save rozanovz/2b19bde7300fedf962d68cafadc9e028 to your computer and use it in GitHub Desktop.

Select an option

Save rozanovz/2b19bde7300fedf962d68cafadc9e028 to your computer and use it in GitHub Desktop.
const removeDigit = (digit, remove) => {
let newDigit = `${digit}`;
if(newDigit.indexOf(remove) === -1) return digit;
let indexes = [];
for (let i = 0; i < newDigit.length; i++){
if(newDigit[i] == remove) indexes.push(i);
}
return Math.max(...indexes.map((i) => {
return `${newDigit.substring(0, i)}${newDigit.substring(i+1)}`
}));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment