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

Basic: Call exersion - a question about no using prototype #210

Open
hungdao-testing opened this issue May 25, 2023 · 1 comment
Open

Basic: Call exersion - a question about no using prototype #210

hungdao-testing opened this issue May 25, 2023 · 1 comment

Comments

@hungdao-testing
Copy link

Hi all,

I have a solution below, the point is I dont use prototype to parse/convert the arguments (such as. Array.prototype.slice.call(arguments)). So I am wondering this way is suitable to the exercise since I am kind of confusing about the phrase in the task which have a property 'quack' defined directly on them

Task:
Write a function duckCount that returns the number of arguments passed to it which have a property 'quack' defined directly on them. Do not match values inherited from prototypes.

My solution

function duckCount() {
    // SOLUTION GOES HERE
    return Object.values(arguments).reduce((prev, curr, index) => {
        if(Object.prototype.hasOwnProperty.call(curr,'quack')){
            prev = prev + 1
        }
        return prev
    }, 0)
  }
@gpetrioli
Copy link

Conditions

  • Do not use any for/while loops or Array#forEach.
  • Do not create any counter/accumulator variables.
  • Do not create any unnecessary functions e.g. helpers.

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

2 participants