Skip to content

Instantly share code, notes, and snippets.

Created July 31, 2016 18:37
Show Gist options
  • Save anonymous/943613a090b92d776b5c7d209e05772d to your computer and use it in GitHub Desktop.
Save anonymous/943613a090b92d776b5c7d209e05772d to your computer and use it in GitHub Desktop.
https://repl.it/CZ17/119 created by sethopia
/*
SHORT STACK
create a function shorten() that takes a number and an array of single-digit integers. shorten() should return the input number, with every digit from the array removed
ex)
shorten(1023, [1,2]) --> 03
shorten(1245267194821, [2,3,4]) --> 15671981
*/
function shorten(num, arr) {
return Number(num.toString().split('').filter(function(digit) {return arr.indexOf(parseInt(digit)) === -1;}).join(''));
}
console.log(shorten(1023, [1,2])); // 03
console.log(shorten(1245267194821, [2,3,4])); // 15671981
Native Browser JavaScript
>>> 3
15671981
=> NaN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment