In my program I have added the Array.prototype.equals() function listed in this SO post.
I have the following function to perform deep-copies of arrays (I am using this strictly for logging purposes - so that I can see what my arrays look like at various points in time in the Chrome console.)
function deepCopy(array) {
return $.extend(true, [], array);
}
I then use this as such:
console.log("Sorting metrics list by metric name...");
console.log("Metrics list before sort:");
console.log(deepCopy(metrics));
metrics.sort(compare);
console.log("Metrics list after sort:");
console.log(deepCopy(metrics));
For reference, my compare function is:
function compare(a, b) {
return a.name.localeCompare(b.name);
}
When I view my metrics array in the Chrome console after the deepCopy(), the equals method defined for the Array.prototype is IN the array! Picture:
As you can see from the screen shot, I check the actual value of the metrics array after everything has run, and it clearly does not contain the equals method. This is my reasoning for believing it has something to do with how jQuery().extend handles copying arrays.
Any ideas on how to fix my deepCopy function to stop this? (Or change my prototype function, if needed.)