0

Below is a simple program to merge 2 arrays. I have used two different ways to solve this problem. How do I calculate runtime complexity, if possible space complexity too, of both these versions? Thanks in advance!

let A = [1, 2, 3];
let B = [2, 3 , 4, 5];

// VERSION: 1
//let C = A.concat(B.filter( item => {return A.indexOf(item) < 0;} ));

// VERSION: 2
let C = [...new Set([...A,...B])];

// result:
console.log(C);

1 Answer 1

2

The answer is lies within a term called Big O Notation. You can find detailed articles below.

In addition, you can use functional programming tools Ramda.js that achieve the same result which is getting the uniq numbers.

let A = [1, 2, 3];
let B = [2, 3 , 4, 5];
const concat = R.concat(A,B);
const result = R.uniq(concat);

console.log(result);

For example

Time Complexity Big O Notation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.