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 map = ([ head, ...tail ], fn) => | |
(head === undefined && !tail.length) ? [] : | |
(tail.length === 0) ? [ fn(head) ] : | |
[ fn(head), ...map(tail, fn) ]; | |
const filter = ([ head, ...tail ], fn) => { | |
const newHead = fn(head) ? [ head ] : []; | |
return tail.length ? [ ...newHead, ...(filter(tail, fn)) ] : newHead; | |
} |
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 timer = time => | |
new Promise(resolve => setTimeout(resolve, time)); |
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
/** | |
* Creates an array with the span of numbers going from `first` and ending at | |
* `last` if possible depending on the specified step value. | |
* @param {number} first | |
* First number that should appear in the returned array. | |
* @param {number} last | |
* Last number that should appear in the returned array. | |
* @param {number=} opt_step | |
* Defaults to `1` if not given or if `0` or `NaN` is specified. The | |
* difference between each subsequent number in the returned array. |
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
Array.prototype.removeDuplicates = function(){ | |
return this.reduce((result,nextItem)=>result.includes(nextItem) ? result : result.concat(nextItem),[]); | |
} |
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 chunk(array, size) { | |
//declaring variable 'chunked' as an empty array | |
let chunked = [] | |
//looping through the array until it has been entirely "manipulated" or split into our subarrays | |
while(array.length > 0) { | |
//taking the spliced segments completely out of our original array | |
//pushing these subarrays into our new "chunked" array | |
chunked.push(array.splice(0, size)) | |
} |
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
Array.prototype.sortBy = function(key, ascending = true) { | |
return this.sort((a, b) => { | |
if (ascending) { | |
return a[key] > b[key] ? 1 : a[key] < b[key] ? -1 : 0; | |
} else { | |
return a[key] > b[key] ? -1 : a[key] < b[key] ? 1 : 0; | |
} | |
}); | |
}; | |
var arr = [ |
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
Math.round(Math.random() * 1E2) |
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
self.addEventListener('install', (e) => { | |
e.waitUntil( | |
caches.open("precache").then((cache) => cache.add("/broken.png")) | |
); | |
}); | |
function isImage(fetchRequest) { | |
return fetchRequest.method === "GET" && fetchRequest.destination === "image"; | |
} |
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 downloadFile(data, fileName, type="text/plain") { | |
// Create an invisible A element | |
const a = document.createElement("a"); | |
a.style.display = "none"; | |
document.body.appendChild(a); | |
// Set the HREF to a Blob representation of the data to be downloaded | |
a.href = window.URL.createObjectURL( | |
new Blob([data], { type }) | |
); |
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
'use strict'; | |
const fs = require('fs'); | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf-8'); | |
let inputString = ''; | |
let currentLine = 0; |
OlderNewer