I've had some really odd results when experimenting with currying in Chromes live browser and am curious why my logs are not coming out as expected.
Why am I getting the same array order when running the code below in Chrome? The code runner injected here in stack overflow IS giving me the correct response, but I have also attached an image of me running this same code directly into the console and it giving incorrect logs back from Chrome?
const people = [
{ age: 15, name: 'Bob' },
{ age: 18, name: 'Adrian' },
]
function custom_sort(key){
return function(a, b){
if (a[key] < b[key]) return -1
else if (a[key] > b[key]) return 1
else return 0
}
}
const sort_name = custom_sort('name')
const sort_age = custom_sort('age')
people.sort(sort_name);
console.log(people);
people.sort(sort_age);
console.log(people);
const people = [
{ age: 15, name: 'Bob' },
{ age: 18, name: 'Adrian' },
]
function custom_sort(key){
return function(a, b){
if (a[key] < b[key]) return -1
else if (a[key] > b[key]) return 1
else return 0
}
}
const sort_name = custom_sort('name')
const sort_age = custom_sort('age')
people.sort(sort_name);
console.log(people);
people.sort(sort_age);
console.log(people);
Actual response when using Chrome: