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

Possible typo at FILTERING exercise from Chapter 04 #216

Open
pedrodrocha opened this issue Sep 12, 2020 · 1 comment
Open

Possible typo at FILTERING exercise from Chapter 04 #216

pedrodrocha opened this issue Sep 12, 2020 · 1 comment
Assignees

Comments

@pedrodrocha
Copy link

Hi,

I was stuck for a while today at the FILTERING exercise from Chapter 04. Couldn't get null at both 'a' and 'e' because the program wasn't considering all the values. Then I realized that at the "test' snippet from the book the values passed while creating "example" weren't in brackets and, so, weren't in an array.

Look:

const example = new Filter('a', 'e', 'i', 'o', 'u') 
for (let value of ['a', 'b', 'c', 'd', 'e']) { 
console.log(value, '->', example.call(value))
}

I was running the code with this solution:

class Filter {
    constructor(vals) {
        this.name = "filter"
        this.values = vals
    }

    call(input){     

        if (this.values.includes(input)){
            return null
        } else {
            return input
        }
    }
}

and getting this result:

a -> null
b -> b
c -> c
d -> d
e -> e

I got the result right by adding the brackets while creating "example". Look:

const example = new Filter(['a', 'e', 'i', 'o', 'u']) 

for (let value of ['a', 'b', 'c', 'd', 'e']) { 
    console.log(value, '->', example.call(value))
}

I don't know if this is really a typo mistake or is just that I am doing this wrong (or both). But thought was important writing this issue in any case.

Thank you all for the book, is helping me a lot getting started with JavaScript !!

Best,
Pedro.

@filippo82
Copy link

Hi @pedrodrocha, I believe you need to write the constructor using the "rest" syntax:

constructor (...args) {
  this.values = args
}

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

3 participants