Skip to content

Instantly share code, notes, and snippets.

View brecht's full-sized avatar
👋
-

Brecht Omey brecht

👋
-
View GitHub Profile
@brecht
brecht / sort-array-of-objects-by-prop.js
Created May 29, 2019 12:03
Sort array of objects by string property
arrayOfObjects.sort(
(a, b) => (a.propName > b.propName) ? 1 : ((b.propName > a.propName) ? -1 : 0)
);
@brecht
brecht / unique-array-of-objects-by-property.js
Last active May 29, 2019 11:55
Remove duplicates from array of objects by property value (es6)
const uniqueArrayByProperty = (collection, property) => [
...new Map(collection.map(element => [element[property], element])).values()
];
// const arrayOfObjects = [{ id: 1, name: 'John' }, { id: 2, name: 'John' }, { id: 3, name: 'Jane' }];
// uniqueArrayByProperty(arrayOfObjects, 'name');
// > [{ id: 2, name: 'John' }, { id: 3, name: 'Jane' }];
@brecht
brecht / is-partly-inview.js
Last active August 29, 2015 14:27
isPartlyInView (vanillaJS)
// inspired by https://gist.github.com/jjmu15/8646226
var isPartlyInView = function isPartlyInView(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (rect.bottom > 0 && rect.top < (window.innerHeight || html.clientHeight));
};