完成代码,使 names 变量包含按字母顺序排列的作者姓名数组,这些作者的图书评级大于MIN_BOOK_RATING变量的值。
const books = [
{
title: "The Last Kingdom",
author: "Bernard Cornwell",
rating: 8.38,
},
{
title: "Beside Still Waters",
author: "Robert Sheckley",
rating: 8.51,
},
{
title: "The Dream of a Ridiculous Man",
author: "Fyodor Dostoevsky",
rating: 7.75,
},
{ title: "Redder Than Blood", author: "Tanith Lee", rating: 7.94 },
{
title: "The Dreams in the Witch House",
author: "Howard Lovecraft",
rating: 8.67,
},
];
const MIN_BOOK_RATING = 8;
// Change code below this line
const names = books
.filter((rating, index, array) => array.indexOf(rating) > MIN_BOOK_RATING)
.map(rating => rating.author)
.sort((a, b) => a.localeCompare(b));
console.log(names)
求助,我想不通。
您的过滤方法有误。需要过滤数组中每个可迭代对象的数据,将当前评分值与MIN_BOOK_RATING进行比较
你做的几乎是对的,只是在过滤书籍时犯了一点错误。并且对于这样的排序,不需要传递排序器,默认情况下数组就是这样排序的。