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
proveWithStats(100000) | |
function proveWithStats(steps) { | |
const winStats = {change: 0, keep: 0} | |
for (let i = 0; i < steps/2; i++) { | |
playRound('keep', winStats) | |
playRound('change', winStats) | |
} | |
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 { existsSync, watch, readFile } = require('fs'); | |
const { dirname, basename } = require('path'); | |
function watchFile(filePath, contentCallback) { | |
const folderPath = dirname(filePath); | |
const folderName = basename(folderPath); | |
const parentPath = dirname(folderPath); | |
const fileName = basename(filePath); | |
let folderExists = existsSync(folderPath); |
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
buildMatrix(3, 4, 5, 'right-up') | |
// [ | |
// [1, 2, 3, 4], | |
// [2, 3, 4, 5], | |
// [3, 4, 5, 6], | |
// ] | |
function buildMatrix0(rCount, cCount, countStart, direction) { | |
const [first, then] = direction.split('-') | |
const matrix = Array(rCount).fill().map(() => []) |
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
/* | |
Task: Minimum required coins to reach the given input amount | |
Given a list of coins: 500, 200, 100, 50, 20, 10, 2, 1, 0.5, 0.2, 0.1, 0.02, 0.01 | |
Given input amount: 3763.58 | |
Expected output: | |
{ | |
500:7, | |
200:1, |
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
sub(mult(2, 5), add(2, div(12, 3))) // 4 | |
function sub(x, y){ | |
return x - y | |
} | |
function mult(x, y){ | |
return x * 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
String.prototype.split_ = function (sep, limit = this.length) { | |
if (sep === undefined) return [String(this)] | |
if (limit === Infinity) return [] | |
const parts = [], length = this.length, len = sep.length | |
const isSepStart = i => { | |
for (let j = 0; j < len; j++) { | |
if (this[i + j] != sep[j]) return false | |
} |
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 decToBin(int) { | |
let bin = '' | |
while (int) { | |
const digit = int % 2 | |
bin = digit + bin | |
int -= digit | |
int /= 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
const rectangle = { | |
a: 4, | |
b: 5, | |
get perimeter() { | |
return this.a * 2 + this.b * 2; | |
}, | |
get area() { | |
return this.a * this.b; | |
}, | |
}; |
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 bagOfRandom = { | |
[Symbol.iterator]: () => ({ | |
next: () => { | |
if (Math.random() <= 0.01) return { done: true } | |
return { value: Math.floor(Math.random() * 100 + 1), done: false } | |
} | |
}) | |
} |
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
prices = [10, 25, 70, 100, 120] | |
discountFuncs = [5, 10, 25, 30] | |
.map(num => x => '$' + (x / 100 * (100-num)).toFixed(2)) | |
discountFuncs.map([].map, prices) | |
// (4) [Array(5), Array(5), Array(5), Array(5)] | |
// 0: (5) ['$9.50', '$23.75', '$66.50', '$95.00', '$114.00'] | |
// 1: (5) ['$9.00', '$22.50', '$63.00', '$90.00', '$108.00'] | |
// 2: (5) ['$7.50', '$18.75', '$52.50', '$75.00', '$90.00'] | |
// 3: (5) ['$7.00', '$17.50', '$49.00', '$70.00', '$84.00'] |
NewerOlder