This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://javascript.info/map-set | |
const uniqueObjectsByProp = (array, prop) => { | |
let map = new Map(array.map(item => [item[prop], item])); | |
return Array.from(map.values()); | |
}; | |
let arr = [{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }, { id: 1, name: 'Item 1' }]; | |
let uniqueArr = uniqueObjectsByProp(arr, 'id'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseVideo (url) { | |
// - Supported YouTube URL formats: | |
// - http://www.youtube.com/watch?v=My2FRPA3Gf8 | |
// - http://youtu.be/My2FRPA3Gf8 | |
// - http://y2u.be/huKvjPQ-Xm4 | |
// - https://youtube.googleapis.com/v/My2FRPA3Gf8 | |
// - http://www.youtube.com/embed/Ab25nviakcw | |
// - http://www.youtube-nocookie.com/v/Ab25nviakcw?version=3&hl=en_US | |
// - http://www.youtube.com/watch?feature=player_embedded&v=Ab25nviakcw# | |
// - Supported Vimeo URL formats: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function saveSelection() { | |
if (window.getSelection) { | |
var sel = window.getSelection(); | |
if (sel.getRangeAt && sel.rangeCount) { | |
return sel.getRangeAt(0); | |
} | |
} else if (document.selection && document.selection.createRange) { | |
return document.selection.createRange(); | |
} | |
return null; |