rockaBe / array_intersect

a simple kata like challenge on how to implement the intersection of 2 arrays (in ruby)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kata like challenge

This challenge is to see how applicants understand requirements and implement a nice solution in nice code.

Background

As a developer, you should be able to calculate the intersects of two arrays (a1, a2) so that the following criterias are met:

  1. all elements, that occur in both arrays, are available in the resulting array.
  2. the resulting array should be sorted

1. main task

Implement an intersect method, without using the built in #intersect method of the class Array, that takes 2 arrays as arguments
a1 = [3,3,1,3] and
a2 = [1,2,3,3] and

returns [1,3].

2. nice-to-have task

Implement the intersect method same as above, but elements commonly appearing multiple times in both arrays should be reflected in the result.

E.g.
a1 = [3,3,1,3] and
a2 = [1,2,3,3] and
returns [1,3,3] (have a look at the digit 3 appearing twice in the result).

talk us through while you implement this

We want to understand how you approach the task and be able to follow, so speaking out your thoughts, helps us understand you better.

Please provide also considerations about e.g. performance, O-notation etc.

About

a simple kata like challenge on how to implement the intersection of 2 arrays (in ruby)

License:GNU General Public License v3.0