0

a newbie question.. Here's my code:

let result = (...ohStr) => {
    let res = []; // edited (before res = [])
    for (const Str of ohStr){
        if(/oh{3,6} no/.test(Str)){
            res.push({Str:true});
        }
        else{
            res.push({Str:false});
        }
    }
        return res;
}

console.log(result("ohhh no","ohhhh no","ohhhhh no","oh no","ohh no"));

The question is why the res array is created like this:

[ { Str: true },
  { Str: true },
  { Str: true },
  { Str: false },
  { Str: false } ]

instead adding the Str value every iteration in for loop? and how I overcome this problem?

asrofil
  • 25
  • 4

0 Answers0