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
{"lastUpload":"2020-05-01T19:06:41.818Z","extensionVersion":"v3.4.3"} |
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 processAll(){ | |
return asyncAction.then(x => waitForEach(y => processFunc(y), x)) | |
} | |
const waitForEach = (processFunc, [head, ...tail]) => { | |
!head | |
? Promise.resolve() | |
: processFunc(head).then(waitForEach(processFunc, tail)) | |
} |
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
const superSet = arr => { | |
var result = []; | |
result.push([]) | |
arr.forEach(val => { | |
let length = result.length; | |
let i = 0; | |
while(i < length){ | |
let newAr = result[i].slice(0); | |
newAr.push(val); | |
result.push(newAr); |
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
if (!Object.is) { | |
Object.is = function ObjectIs(x, y) { | |
if (x === y) { | |
return x !== 0 || 1/x === 1/y | |
} else { | |
return x !== x && y !== y; | |
} | |
} | |
} |
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 checkSign(x){ | |
return x !== 0 ? Math.sign(x) : Object.is(x, -0) ? -1 : 1; | |
} | |
checkSign(-0) // -1 i.e. -ve sign | |
checkSign(0) // 1 i.e. +ve sign | |
checkSign(-6) // -1 | |
checkSign(6) // 1 | |
credits: Kyle Simpson (getify) |
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 plusplus(orig_x){ | |
let orig_x_changed = Number(orig_x); | |
x = orig_x_changed + 1; | |
return orig_x_changed; | |
} | |
let x = '2'; | |
plusplus(x); // 2 | |
x; // 3 |
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
//ES6 | |
function spiral(matrix) { | |
const arr = []; | |
while (matrix.length) { | |
arr.push( | |
...matrix.shift(), | |
...matrix.map(a => a.pop()), | |
...(matrix.pop() || []).reverse(), | |
...matrix.map(a => a.shift()).reverse() |
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 array_intersect(){var a,b,c,d,e,f,g=[],h={},i;i=arguments.length-1;d=arguments[0].length;c=0;for(a=0;a<=i;a++){e=arguments[a].length;if(e<d){c=a;d=e}}for(a=0;a<=i;a++){e=a===c?0:a||c;f=arguments[e].length;for(var j=0;j<f;j++){var k=arguments[e][j];if(h[k]===a-1){if(a===i){g.push(k);h[k]=0}else{h[k]=a}}else if(a===0){h[k]=0}}}return g} |
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 textSize(text) { | |
if (!d3) return; | |
var container = d3.select('body').append('svg'); | |
container.append('text').attr('x', -99999).attr('y',-99999).text(text); | |
var size = container.node().getBBox(); | |
container.remove(); | |
return { width: size.width, height: size.height }; | |
} | |
// Usage: textSize("This is a very long text"); |
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://reqres.in/ | |
http://www.omdbapi.com/ |
NewerOlder