Skip to content

Instantly share code, notes, and snippets.

@Wockeez
Last active November 6, 2021 03:36
Show Gist options
  • Save Wockeez/5ca539a624e6d60e75b879985ce2bc9b to your computer and use it in GitHub Desktop.
Save Wockeez/5ca539a624e6d60e75b879985ce2bc9b to your computer and use it in GitHub Desktop.
Самые короткие однострочные вкладыши для ES6+
Найдите уникальные id's в массиве.
arr.filter((v,i,a)=>a.findIndex(t=>(t.id === v.id))===i)
Уникальный по нескольким свойствам ( place и name )
arr.filter((v,i,a)=>a.findIndex(t=>(t.place === v.place && t.name===v.name))===i)
Уникальный по всем свойствам (это будет медленно для больших массивов)
arr.filter((v,i,a)=>a.findIndex(t=>(JSON.stringify(t) === JSON.stringify(v)))===i)
Сохраните последнее событие.
arr.slice().reverse().filter((v,i,a)=>a.findIndex(t=>(t.id === v.id))===i).reverse()
Фильтр по алфавиту
arr.sort((a, b) => a.name > b.name ? 1 : -1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment