Multikey Sort: Can I use arr.sort() method?


#1

Seems like the multikey sorting challenge can be easily solved with the arr.sort() compare function shown below. Is this challenge meant to be solved differently? More harder way?

    var Arr = [{"First Name": "Felix", "Last Name": "Williamson"},
               {"First Name": "Roman", "Last Name": "Jhonson"},
               {"First Name": "Jhonny", "Last Name": "Jhonson"},
               {"First Name": "Sergey", "Last Name": "Jhonson"},
               {"First Name": "Dylan", "Last Name": "Popach"},
               {"First Name": "Mark", "Last Name": "Jhonson"},
               {"First Name": "Mark", "Last Name": "Karlson"}];
    function MultikeySort(Obj){
		let Name = Object.keys(Obj[0]);
		if (!Array.isArray(Obj)){
			return "INVALID INPUT";
		}
        if (Object.keys(Obj[0]).lgth === 0){
            return Obj;
        }
        Obj.sort (
            function (a, b){  //using arr.sort comparefunction 
                if (a[Name[1]] < b[Name[1]]){
                    return -1;              
                }
                else if (a[Name[1]] > b[Name[1]]){
                    return 1;            
                }else{
                    if (a[Name[0]] < b[Name[0]]){
						return -1;              
					}
					else if (a[Name[0]] > b[Name[0]]){
						return 1;
					}
					else{
						return 0;
					}
                }
            }
        );
        return Obj;
    }

    console.log(MultikeySort(Arr));