以下は、いくつかのプロパティでオブジェクトの配列をソートする関数です。
function createCompareFunc(propertyName){
return function(obj1, obj2){
var val1=obj1[propertyName];
var val2=obj1[propertyName];
return val1-val2;
}
}
var data=[{name:'a', age:12},{name:'b',age:5}];
console.log(typeof data[0]['age']); //number
console.log(data.sort(createCompareFunc('name')));
//[Object{name="a", age=12},Object{name="b",age=5}]
console.log(data.sort(createCompareFunc('age')));
//[Object{name="a", age=12},Object{name="b",age=5}], but I want to get '[Object{name="b",age=5},Object{name="a", age=12}]'
番号の何が問題になっていますか?