I'm curious if this is the right way of going about the issue: function sortWordsByIncorrectAnswers(array) {    array = array.slice(0)    var sortedArray = array.sort(function (a, b) {        a = a.fields.false;        b = b.fields.false;        return a < b ? -1 : a > b ? 1 : 0;    });    return sortedArray}I want to return a new version of the array, and not change 'array' passed into the method (deep copy).This works as I want it to, but is this the correct way of doing this? It seems off.
Deep reference and object passing
javascript;reference
.slice() does not actually do a deep copy, the easiest way to do a deep copy with simple objects is array = JSON.parse( JSON.stringify( array ) )Also, you can sort on a boolean in a simpler way:function sortWordsByIncorrectAnswers(array){  array =  JSON.parse( JSON.stringify( array || [] ) );  return array.sort( function(a, b)  {    return a.fields.false - b.fields.false;  });}