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 markov<T>(findFirst: () => T[][], findNext: (previous: T) => T[][]): T[][] { | |
| function chooseRandom<T>(xs: T[]): T { | |
| return xs[Math.floor(Math.random() * xs.length)]; | |
| } | |
| function last<T>(xs: T[]): T { | |
| return xs[xs.length - 1]; | |
| } | |
| var result: 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
| interface ILocale { | |
| langCode: string; | |
| langName: string; | |
| groups: { | |
| groupName: string, | |
| translates: { | |
| source: string, | |
| translate: string | |
| }[] | |
| }[]; |
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
| interface Functor<A> { | |
| map<B>(f: (a: A) => B): Functor<B>; | |
| } | |
| interface Monad<A> extends Functor<A> { | |
| map<B>(f: (a: A) => B): Monad<B>; | |
| bind<B>(f: (a: A) => Monad<B>): Monad<B>; | |
| } | |
| interface Eq<A> { |
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 p = console.log.bind(console); | |
| var q = require('readline-sync').question; | |
| var gcd = (a, b) => !b ? a : gcd(b, a % b); | |
| var r = () => Math.floor(Math.random()*9)+1 | |
| var i = 1; | |
| for(;;) { | |
| var x = r(); | |
| var y = r(); | |
| var df = x % y === 0; | |
| if(df) continue; |
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 p = console.log.bind(console); | |
| var q = require('readline-sync').question; | |
| var r = () => Math.floor(Math.random()*15)+1 | |
| var i = 1; | |
| for(;;) { | |
| var x = r(); | |
| p(`(${i}) ${Math.pow(x, 2)}`); | |
| var a = parseInt(q('Input the answer: ')); | |
| var c = a === x; | |
| p(c ? 'Good!' : `Bad: The correct answer is ${x}`); |
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
| // Task | |
| const logTask = Task.sync<string, void>(text => console.log(text)); | |
| const taskA = Task.delay(1000).map(() => 1 + 2 + 3).map(String); | |
| const taskB = Task.resolve('Hello'); | |
| Task.all([taskA, taskB]).map(xs => xs.join(', ')).next(logTask).run(); | |
| Task.race([taskA, taskB]).next(logTask).run(); | |
| // Promise | |
| const logPromise = (text: string) => console.log(text); | |
| const promiseA = new Promise<void>(resolve => setTimeout(resolve, 1000)).then(() => 1 + 2 + 3).then(String); |
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
| Task.delay(1000).next(() => print('Yeah')); |
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
| const { value, stories } = new Writer(3, ['3']) | |
| .write(x => [x * 5, '* 5']) | |
| .write(x => [x + 3, '+ 3']); | |
| print(value).next(() => print(stories.join(' '))).run(); | |
| // Output: | |
| // 18 | |
| // 3 * 5 + 3 |
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 quicksort([x, ...xs]: number[]): number[] { | |
| return typeof x === 'undefined' ? [] : (() => { | |
| const smallerSorted = quicksort(xs.filter(a => a <= x)); | |
| const biggerSorted = quicksort(xs.filter(a => a > x)); | |
| return [...smallerSorted, x, ...biggerSorted]; | |
| })(); | |
| } |
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 canvas; | |
| var ctx; | |
| var x; | |
| var y; | |
| var isRightPressed; | |
| var isLeftPressed; | |
| var isUpPressed; | |
| var isDownPressed; | |
| window.addEventListener('load', function() { |