Skip to content

Arrow function in the "quotient" object example not working correctly #1

Description

@NaderBhrr

I was trying to understand how the "quotient" object works.

const quotient = {
  numbers: [1, 2, 3, 4, 5, 6, 7],
  results: [ ],
  divideFn: function (divisor) {
    return this.numbers.map(function (divident) {
      if (divident % divisor === 0) {
        return this.results.push(divident);
      }
    });
  },
};

But I don't see any reason for returning values when you use "push" to place values in the results array.

Secondly, if you call the "DivideFn" more than once you will get undesirable results, fore example:

quotient.divideFn(3)
const byThree = quotient.results

quotient.divideFn(2)
const byTwo = quotient.results

I'd be thankful if you explain your thought process

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