Created
July 31, 2016 18:37
-
-
Save anonymous/943613a090b92d776b5c7d209e05772d to your computer and use it in GitHub Desktop.
https://repl.it/CZ17/119 created by sethopia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Native Browser JavaScript | |
>>> 3 | |
15671981 | |
=> NaN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment