-
-
Notifications
You must be signed in to change notification settings - Fork 681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jsPsych.randomization.shuffle does not return a deep copy #2808
Comments
Thanks @ChristopheBossens, I think we should fix this with 8.0. @bjoluc what do you think? |
Thanks @ChristopheBossens! I added c9326e3 after reading the issue for the first time, but I misread the issue: I thought maybe the original array would be modified by On a second read, I understand the issue now and I think I have to disagree: Shuffle does just what it says it does – it "Returns an array with the same elements as the input array in a random order". Why should it create a deep copy? |
@bjoluc In this specific case we had an array of dictionaries that needed to be shuffled, and in the shuffled array the values in some of these dictionaries needed to be updated. Without a deep copy, changing a dictionary in the shuffled array also updates that same dictionary in the original array. So the definition is correct in the sense (they are the same elements), but without a deep copy they are literally the same elements when dealing with arrays/dictionaries. I was wondering if that is what is intended? In the discussion above, we handled this by adding the following code before shuffling:
With this code, we can write
and this will only update that element in So the question is basically if this is something that should be handled by the framework, or perhaps add a disclaimer that the shuffling algorithm will not create a deep copy (and how to deal with that situation if you do need a deep copy)? |
There are situations where |
Turns out |
While answering the question #2794 in the discussion forum, I noticed that the jsPsych.randomization.shuffle function does not create a deep copy of the array that is passed. For example
Would shuffle the array, but using
survey_1_questions[0]['prompt'] = 'test';
affects the item in both arrays.
Is this something that should be fixed?
The text was updated successfully, but these errors were encountered: