@hatealleverything

Как в массиве с одинаковым полем отсортировать данные по цене и удалить наименьшие из массива?

Добрый день.
Не доходит как можно в массиве с одинаковым полем отсортировать данные по цене и удалить наименьший из массива
[{ name: "Creeper's Cruel Painsaw", price: '2.53', rarity: 'Common' },
{ name: "Creeper's Cruel Painsaw", price: '2.50', rarity: 'Common' },
{ name: 'Cuffs of Oak and Yew', price: '3.94', rarity: 'Rare' },
{ name: 'Cuffs of Oak and Yew', price: '4.99', rarity: 'Rare' },
{ name: 'Curled Root-Staff', price: '2.91', rarity: 'Common' },
{ name: 'Curled Root-Staff', price: '3.33', rarity: 'Common' }]
  • Вопрос задан
  • 121 просмотр
Пригласить эксперта
Ответы на вопрос 1
MagnusDidNotBetray
@MagnusDidNotBetray
Самый елеустремленный человек
const arr = [{ name: "Creeper's Cruel Painsaw", price: '2.53', rarity: 'Common' },
{ name: "Creeper's Cruel Painsaw", price: '2.50', rarity: 'Common' },
{ name: 'Cuffs of Oak and Yew', price: '3.94', rarity: 'Rare' },
{ name: 'Cuffs of Oak and Yew', price: '4.99', rarity: 'Rare' },
{ name: 'Curled Root-Staff', price: '2.91', rarity: 'Common' },
{ name: 'Curled Root-Staff', price: '3.33', rarity: 'Common' }];

const sorted = [...arr].sort((a, b) => a.price - b.price).slice(1);
console.log(sorted); /* [
	{ name: "Creeper's Cruel Painsaw", price: "2.53", rarity: "Common" },
  { name: "Curled Root-Staff", price: "2.91", rarity: "Common" },
  { name: "Curled Root-Staff", price: "3.33", rarity: "Common" },
  { name: "Cuffs of Oak and Yew", price: "3.94", rarity: "Rare" },
  { name: "Cuffs of Oak and Yew", price: "4.99", rarity: "Rare" }
] */
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
19 апр. 2024, в 16:53
1000 руб./за проект
19 апр. 2024, в 16:45
5000 руб./за проект
19 апр. 2024, в 16:22
30000 руб./за проект