curl https://gist.githubusercontent.com/chrisdothtml/509fdbe3bfec1a11bbc346e4b44c3604/raw/switch-npmrc.js > "$HOME/switch-npmrc.js"
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
[ | |
{ | |
"key": "cmd+y", | |
"command": "redo", | |
"when": "editorTextFocus && !editorReadonly" | |
}, | |
{ | |
"key": "shift+alt+down", | |
"command": "" | |
}, |
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
{ | |
"iterations": 100 | |
} |
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
/** | |
* Generate Set of prime numbers up to `maxPrime` | |
* https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes | |
* | |
* @param {Number} maxPrime | |
* @returns {Set} | |
*/ | |
function getPrimes (maxPrime) { | |
const sieve = new Map | |
const result = new Set |
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
/** | |
* Generate fibonacci sequence up to `maxNum` | |
* https://en.wikipedia.org/wiki/Fibonacci_number | |
* | |
* @param {number} maxNum | |
*/ | |
function fibonacci (maxNum) { | |
const result = [0, 1] | |
let newNum, index |
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
/** | |
* Generate Recamán sequence up to `maxNum` | |
* https://youtu.be/FGC5TdIiT9U | |
* | |
* @param {Number} maxNum | |
* @returns {Set} | |
*/ | |
function recaman (maxNum) { | |
const result = new Set([0]) | |
let current, hop |
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
/** | |
* Get all factors of a number | |
* | |
* @param {Number} num | |
* @returns {Set} | |
*/ | |
function getFactors (num) { | |
const numRoot = Math.sqrt(num) | |
const isEven = num % 2 === 0 | |
const incr = isEven ? 1 : 2 |
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
/** | |
* Indicates whether the sum of the factors of a number | |
* are equal to the number | |
* https://en.wikipedia.org/wiki/Perfect_number | |
* | |
* @param {Number} num | |
* @returns {Boolean} | |
*/ | |
function isPerfectNumber (num) { | |
const numRoot = Math.sqrt(num) |
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
/* | |
* Calculate the persistence of a number; | |
* based on Numberphile video: | |
* https://www.youtube.com/watch?v=Wim9WJeDTHQ | |
*/ | |
function calculatePersistence (num) { | |
let result = 1 | |
while ((num = multiplyItems(getDigits(num))) > 0) | |
result++ | |
return result |
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 getPipedInput () { | |
return new Promise(resolve => { | |
let result = '' | |
process.stdin.resume() | |
process.stdin.setEncoding('utf8') | |
process.stdin.on('data', chunk => (result += chunk)) | |
process.stdin.on('end', () => resolve(result)) | |
}) | |
} |
OlderNewer