Skip to content
Advertisement

How can I check if 2 given stacks has the same values? (Not necessarily in the same order)

everybody. How can I check if 2 stacks has the same values?

For example, in stack1 I have [1,3,4,5] and in stack2 I have [4,3,1,5], so the stacks has the same values and the methood needs to return true.

In addition, the stacks must be (in the end) as they were given (with the original values and the same order).

I have started to work on it but unfortuantely it’s not working good:

JavaScript

Thanks in advance.

Advertisement

Answer

One simple way is to use the Collection functionality:

JavaScript

For completeness here is another solution using Collection functionality. It is based on the partial solution posted by @user7:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement