Skip to content

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

Closed
@jpsollie

Description

@jpsollie

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions