This file contains hidden or 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
// if no duplicate in the first list | |
a1.concat( a2.filter( i => a1.indexOf( i ) === -1 ) ); | |
// if duplicate in the first list | |
a1.concat( a2 ).reduce( function( p, c, i, a ) { | |
if ( p.indexOf( c ) === -1 ) p.push( c ); | |
return p; | |
}, [] ); |
This file contains hidden or 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 shuffle( a ) { | |
var m = a.length, t, i; | |
while ( m ) { | |
i = Math.floor( Math.random() * m-- ); | |
t = a[ m ]; | |
a[ m ] = a[ i ]; | |
a[ i ] = t; | |
} |
This file contains hidden or 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
"abcdefghijklmnopqrstuvwxyz".match( /.{1,4}/g ); | |
// [ "abcd", "efgh", "ijkl", "mnop", "qrst", "uvwx", "yz" ] |
This file contains hidden or 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
let partition = ( a, n ) => a.length ? [ a.splice( 0, n ), ...partition( a, n ) ] : []; | |
partition( [ 1, 2, 3, 4, 5, 6, 7, 8 ], 2 ); | |
// [ | |
// [ 1, 2 ], | |
// [ 3, 4 ], | |
// [ 5, 6 ], | |
// [ 7, 8 ] | |
// ] |
This file contains hidden or 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
var matrix = [], | |
H = 4, // 4 rows | |
W = 6; // of 6 cells | |
for ( var y = 0; y < H; y++ ) { | |
matrix[ y ] = []; | |
for ( var x = 0; x < W; x++ ) { | |
matrix[ y ][ x ] = "foo"; | |
} | |
} |
This file contains hidden or 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
var average = arr => arr.reduce( ( p, c ) => p + c, 0 ) / arr.length; | |
average( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ); | |
// 5 |
This file contains hidden or 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
var nodes = [ | |
{ | |
links: [ 1 ], // node 0 is linked to node 1 | |
visited: false | |
}, { | |
links: [ 0, 2 ], // node 1 is linked to node 0 and 2 | |
path: [], | |
visited: false | |
}, | |
... |
This file contains hidden or 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
class TimeTracker { | |
constructor() { | |
this.timers = {}; | |
} | |
logLoadTimes() { | |
var loadTimes = chrome.loadTimes(); | |
console.log( `commitLoadTime .............. ${( loadTimes.commitLoadTime - loadTimes.startLoadTime ).toFixed( 2 )}s` ); | |
console.log( `finishDocumentLoadTime ...... ${( loadTimes.finishDocumentLoadTime - loadTimes.startLoadTime ).toFixed( 2 )}s` ); |
This file contains hidden or 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() { | |
console.clear(); | |
var loadTimes = chrome.loadTimes(); | |
console.log( "requestTime................. " + ( loadTimes.startLoadTime - loadTimes.requestTime ).toFixed( 2 ) + 's' ); | |
console.log( "commitLoadTime.............. " + ( loadTimes.commitLoadTime - loadTimes.startLoadTime ).toFixed( 2 ) + 's' ); | |
console.log( "finishDocumentLoadTime...... " + ( loadTimes.finishDocumentLoadTime - loadTimes.startLoadTime ).toFixed( 2 ) + 's' ); | |
console.log( "finishLoadTime.............. " + ( loadTimes.finishLoadTime - loadTimes.startLoadTime ).toFixed( 2 ) + 's' ); | |
})() |
This file contains hidden or 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
var SD = { | |
create: function( tag, attrs ) { | |
tag = document.createElement( tag ); | |
for ( var attr in attrs ) tag[ attr ] = attrs[ attr ]; | |
return tag; | |
}, | |
get: function( selector, context, undefined ) { | |
var matches = { |