Skip to content
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

rest operator issue (occured in learnyounode, but seems not related) #33721

Closed
jpsollie opened this issue Jun 4, 2020 · 1 comment
Closed

Comments

@jpsollie
Copy link

jpsollie commented Jun 4, 2020

What steps will reproduce the bug?

in learyounode, excersise 2, working with rest operator:

let begin = 0;  
let {,,...numbersl} = process.argv;  
for(let i in numbersl) {
          begin += Number(i);
          };  
console.log(begin);

gives an error "numbersl is not iterable".

when digging into the code:

let begin = 0;  
let {ax,bx,...numbersl} = process.argv;  
/*for(let i of numbersl) {  
       begin = (begin + Number(i));  
}*/
console.log(numbersl);

the answer is:

node baby-steps.js 1 2 3
{
 '0': '/usr/bin/node',
 '1': '/tmp/baby-steps.js',
 '2': '1',
 '3': '2',
 '4': '3'
}

...whereas you would expect the 0 and 1 to be removed from numbersl

How often does it reproduce? Is there a required condition?

tried several times, occurs every time

What is the expected behavior?

argument 0 and 1 are removed from numbersl

What do you see instead?

arguments are still included

Additional information

@jpsollie
Copy link
Author

jpsollie commented Jun 4, 2020

sorry, the error is mine:
let {ax,bx,...numbersl} = process.argv;
had to be:
let [ax,bx,...numbersl] = process.argv;
because argv is an array, not an object. My bad

@jpsollie jpsollie closed this as completed Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant