Skip to content

Instantly share code, notes, and snippets.

View hg-pyun's full-sized avatar
🎯
Focusing

Haegul Pyun hg-pyun

🎯
Focusing
View GitHub Profile
// ES6
function* foo(){
yield bar();
}
// ES5 Compiled
"use strict";
var _marked = /*#__PURE__*/ regeneratorRuntime.mark(foo);
@hg-pyun
hg-pyun / async-wait.01.js
Created October 7, 2018 05:05
async-wait.01.js
// ES7
async function foo() {
await bar();
}
// ES5 complied
let foo = (() => {
var _ref = _asyncToGenerator(function*() {
yield bar();
});
@hg-pyun
hg-pyun / iterator.08.js
Created October 4, 2018 15:39
iterator.08.js
function* fibonacci() {
let [prev, curr] = [1, 1];
while (true) {
[prev, curr] = [curr, prev + curr];
yield curr;
}
}
for (let n of fibonacci()) {
console.log(n);
@hg-pyun
hg-pyun / iterator.07.js
Created October 4, 2018 15:32
iterator.07.js
function* idMaker(){
var index = 0;
while(index < 3)
yield index++;
}
const gen = idMaker();
console.log(gen.next().value); // 0
console.log(gen.next().value); // 1
@hg-pyun
hg-pyun / iterator.05.js
Created October 4, 2018 15:15
iterator.05.js
const arr = [...Array(100).keys()].map(i => 0);
console.log(arr);
@hg-pyun
hg-pyun / iterator.04.js
Created October 4, 2018 15:12
iterator.04.js
const arr = [];
for(let i=0; i<100; i++) {
arr.push(0);
}
console.log(arr);
@hg-pyun
hg-pyun / iterator.03.js
Created October 4, 2018 14:58
iterator.03.js
const iterable = {
[Symbol.iterator]() {
return {
i: 0,
next() {
if (this.i < 3) {
return { value: this.i++, done: false };
}
return { value: undefined, done: true };
}
@hg-pyun
hg-pyun / iterator.02.js
Last active October 4, 2018 14:53
iterator.02.js
function makeRangeIterator(start = 0, end = Infinity, step = 1) {
var nextIndex = start;
var n = 0;
var rangeIterator = {
next: function() {
var result;
if (nextIndex < end) {
result = { value: nextIndex, done: false }
} else if (nextIndex == end) {
@hg-pyun
hg-pyun / iterator.01.js
Created October 4, 2018 14:25
iterator.01.js
/* array */
let iterable = [10, 20, 30];
for (let value of iterable) {
console.log(value); // 10 20 30
}
/* string */
let iterable = "boo";
@hg-pyun
hg-pyun / currying.13.js
Created September 16, 2018 12:52
currying.13.js
renderHtmlTag = tagName => content => `<${tagName}>${content}</${tagName}>`
renderDiv = renderHtmlTag('div')
renderH1 = renderHtmlTag('h1')
console.log(
renderDiv('this is a really cool div'),
renderH1('and this is an even cooler h1')
)