Skip to content

Instantly share code, notes, and snippets.

View indongyoo's full-sized avatar
🎯
Focusing

유인동 indongyoo

🎯
Focusing
View GitHub Profile
<!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;
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]();
@indongyoo
indongyoo / images.js
Created February 16, 2018 13:20
같이 있어야할 images.js
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_
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}
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 }
}
}
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' }
};
new Promise(function(resolve) {
setTimeout(function() {
resolve('hi');
}, 1000);
}).then(function(val) {
console.log(val); // 1초 뒤 hi
});
new Promise(function(resolve) {
setTimeout(function() {
const log = console.log;
var a = 10;
function f1(a2) {
a2 = 5;
log(a2); // 5
log(a); // 10
}
f1(a);
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}
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())
: