Mengurutkan nilai array sesuai nilai yang sama dengan array lain

gmna ya cara mengurutkan nilai array people sesuai dari array sharon?

const interestList = [
  "gaming",
  "driving",
  "football",
  "fishing",
  "painting",
  "cooking",
  "singing",
  "shopping",
  "running",
  "clubbing"
];

const people = [
  { name: "Ahmad",    interests: ["shopping", "painting", "cooking"] },
  { name: "Betty",    interests: ["running", "painting", "football"] },
  { name: "Charlie",  interests: ["gaming", "football", "painting"] },
  { name: "Diana",    interests: ["fishing", "singing", "driving"] },
  { name: "Ethan",    interests: ["gaming", "clubbing", "cooking"] },
  { name: "Farhan",   interests: ["cooking", "driving", "fishing"] },
  { name: "Gwen",     interests: ["singing", "fishing", "gaming"] },
  { name: "Helen",    interests: ["football", "clubbing", "shopping"] },
  { name: "Imelda",   interests: ["painting", "running", "football"] },
  { name: "Josef",    interests: ["shopping", "running", "cooking"] },
  { name: "Khan",     interests: ["fishing", "running", "clubbing"] },
  { name: "Lionel",   interests: ["gaming", "singing", "driving"] }
];

const sharon = {
  name: "Sharon",
  interests: ["football", "painting", "gaming"]
};

function getSortedList() {
  let output = people.slice();


  return output;
}

function printPeople() {
  let list = getSortedList();
  list.unshift(sharon);
  list.forEach(person => {
    person.interest1 = person.interests[0];
    person.interest2 = person.interests[1];
    person.interest3 = person.interests[2];
    delete person.interests;
  });
  console.log("Friend Matching Script Output:");
  console.table(list);
}

printPeople();

avatar RabilDarmawan
@RabilDarmawan

25 Kontribusi 2 Poin

Dipost 4 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban