0

How can you take in two arrays and compare it then replace one with another.
Example: let say I have 2 arrays: theArray1, theArray2.

let theArray1 = ['Sam', 'jessica', 'theStore'];
let theArray2 =['sam', 'Jessica #' , 'TheStore'];

The two arrays look like they are the same, but they're not. let make theArray1 the reference. What is the most efficient way to turn theArray2 into theArray1 so that I can do this:

expect(theArray1).to.be.equalTo(theArray2).

I tried copy another array that take theArray1 as reference, but that is not the problem. The problem is I want to manipulate theArray2 to make it the same as theArray1.

guppies999
  • 35
  • 4
  • Other than some basic syntax issues, a simple for loop to copy items from one array to another would work. However, this appears to be a unit test. I suspect the 'correct' answer is that the test _should_ have failed in this case. It seems like you're trying to solve the wrong problem. – p.s.w.g Feb 11 '19 at 21:53
  • It will never work unless you do `let theArray2 = theArray1;`, since that will most likely use `===` to compare them. See [How to compare arrays in JavaScript?](https://stackoverflow.com/q/7837456/215552). – Heretic Monkey Feb 11 '19 at 21:59
  • Possible duplicate of [How to compare arrays in JavaScript?](https://stackoverflow.com/questions/7837456/how-to-compare-arrays-in-javascript) – Heretic Monkey Feb 11 '19 at 21:59

0 Answers0