-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Digitize (variadic) #160
Comments
Isn't the |
But what if user needs to input two digit numbers? Then it will not work as third snippet in issue is! |
The function signature indicates that only one argument should be passed. If we want to convert to a variadic function, we should do something like (off the top of my head, test this): const digitize = (...args) => ['',...args].join('').split('').map(i => parseInt(i)); That one should work for variadic arguments. |
Then also whole two digit number is not going to be selected in array.
|
Not at all, the result is exactly as intended. It's suppose to split a number (or numbers) into an array of digits. |
I thought it should be like supporting two digit value also. No problem if the main reason is to split out a single digit number. |
The original idea was to split one number into digits (which has valid use-cases as far as I can tell, had to do this in the past). I don't know if we have to make this variadic, as I can't remember the last time I had to digitize a bunch of numbers in the same array, plus you can digitize multiple values by sticking them in an Array and calling |
Okay got it about the original idea ! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for any follow-up tasks. |
https://github.com/Chalarangelo/30-seconds-of-code#number-to-array-of-digits
Here I found out one bug/caveat! Compare these two code,
So here's the bug where user wants to input in separated manner with ',' then function will not work. Also in first code, user wants to insert multiple values which has more than two digits then,
So definitely depends how user inputs. So we should write in desc. that user should enter input in specific manner so that it returns as pure
The text was updated successfully, but these errors were encountered: