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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
<script src="pre.fn.js"></script> | |
<script src="images.js"></script> | |
<style> | |
.container { | |
border: 1px solid black; |
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 then(f, a) { | |
return arguments.length == 1 ? | |
a => then(f, a) : | |
a instanceof Promise ? a.then(f) : f(a); | |
} | |
function toIterator(data) { | |
if (data == null) data = []; | |
if (!data[Symbol.iterator]) data = Object.values(data); | |
return data[typeof data.values == 'function' ? 'values' : Symbol.iterator](); |
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
var imageDatas = [{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_0.png","x":0,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_1.png","x":32,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_2.png","x":64,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_3.png","x":96,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_4.png","x":128,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_5.png","x":160,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_6.png","x":192,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_7.png","x":224,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_8.png","x":256,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_9.png","x":288,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_10.png","x":320,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_ |
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
log(String.prototype[Symbol.iterator]); | |
// ƒ [Symbol.iterator]() { [native code] } | |
log(Array.prototype[Symbol.iterator]); | |
// ƒ values() { [native code] } | |
const iterable1 = [1, 2]; | |
const iterator1 = iterable1[Symbol.iterator](); | |
log(iterator1.next()); // {value: 1, done: false} | |
log(iterator1.next()); // {value: 2, 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
function reverseIterator(list) { | |
var cur = list.length; | |
return { | |
[Symbol.iterator]: function() { return this; }, | |
next: () => cur-- > 0 ? | |
{ value: list[cur], done: false } : | |
{ value: undefined, done: true } | |
} | |
} |
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 *valuesIter(obj) { | |
for (const key in obj) yield obj[key]; | |
} | |
const users = { | |
5: { id: 5, name: 'YB' }, | |
19: { id: 19, name: 'BX' }, | |
27: { id: 27, name: 'MD' } | |
}; |
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
new Promise(function(resolve) { | |
setTimeout(function() { | |
resolve('hi'); | |
}, 1000); | |
}).then(function(val) { | |
console.log(val); // 1초 뒤 hi | |
}); | |
new Promise(function(resolve) { | |
setTimeout(function() { |
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 log = console.log; | |
var a = 10; | |
function f1(a2) { | |
a2 = 5; | |
log(a2); // 5 | |
log(a); // 10 | |
} | |
f1(a); |
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 } = Functional; | |
console.log( map(a => a + 1, [1, 2]) ); | |
// [2, 3] | |
console.log( map(a => a + 1, {a: 1, b: 2}) ); | |
// {a: 2, b: 3} | |
console.log( map(a => a + 1, new Map([['a', 1], ['b', 2]])) ); | |
// Map(2) {"a" => 2, "b" => 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
const map = curry2((f, coll) => | |
coll instanceof Function ? | |
(..._) => f(coll(..._)) | |
: | |
coll instanceof Promise ? | |
coll.then(f) | |
: | |
coll instanceof Map ? | |
reduce((m, [k, v]) => then(val => m.set(k, val), f(v)), new Map, coll.entries()) | |
: |
OlderNewer