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

Added equality function to Bag, and added unit tests #122

Open
wants to merge 1 commit into
base: release
Choose a base branch
from

Conversation

nchlsb
Copy link

@nchlsb nchlsb commented Jul 19, 2021

I saw that Bag did not have an equality function yet. I'm submitting an implementation that is imperative and optimized because I assume that is desired, but below is more declarative solution as well. Both pass the three unit tests included in this pull request.

equals(bag: Bag<T>): boolean {
        let allKeysSet = this.toSet();
        allKeysSet.union(bag.toSet());
        const allKeysArray = allKeysSet.toArray();
        return allKeysArray.every(element => this.count(element) === bag.count(element));
    }

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

Successfully merging this pull request may close these issues.

None yet

1 participant