0

I have two arrays of the same size, A and B. What would be the fastest way to replace all elements in A that have value equal to y to change and be become equal to z?

The arrays are not small in terms of size.

I can think of a simple for loop along with using array.get and then array.set, but this is not very efficient and is slow, so I was wondering if there is a way without using a loop.

If this is too easy, then would it be possible to also do the same thing for the case that elements in the array are less than equal to y (instead of only being equal)?

sey eeet
  • 229
  • 2
  • 8
  • to replace all elements with the same value you can use `array.fill()` function, to change array with different values you can use`for...in` loop. (It is allowed to modify the array's elements or its size inside the loop). – Starr Lucky Dec 13 '22 at 08:31

0 Answers0