這是以下數組的對象。如何對與名稱相同的對象中的整數值相關的名稱數組進行排序?
function Employee (name,preference,man,max){
// Defines the object employee with the relevant fields
this.name = name;
// slot preference in order
this.preference = preference;
// Number of mandatory slots required
this.man = man;
// Maximum number of slots that can be allocated
this.max = max;
}
這是下面的數組。第二個字段值(表示時間表中的插槽)已按優先順序排序。我希望能夠選擇一個特定的插槽並提醒一個列表,其中包含所有在其偏好字段中擁有該列表的人以及按照最高優先級列出的人的順序。
var staff = new Array();
staff.push(new Employee("john",[1,2,3],1,3));
staff.push(new Employee("Conrad",[2,1,4],1,3));
staff.push(new Employee("Elliot",[8,2,6,7,1],3,5));
staff.push(new Employee("Sarah",[3,1,4,2,6],3,5));
staff.push(new Employee("Emily",[7,2,8,1,4],3,5));
staff.push(new Employee("Mark",[3,4,1,2],1,3));
staff.push(new Employee("Lucy",[5,1,4],1,3));
staff.push(new Employee("Sam",[6,2,7],1,3));
showEmployees(staff);
謝謝這已經幫助了很多: – 2014-11-26 09:41:54