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 test() { | |
const data = [ | |
['오백삼십조칠천팔백구십만천오백삼십구', '삼조사천이만삼천구'], | |
['육십사억삼천십팔만칠천육백구', '사십삼'], | |
['구백육십조칠천억팔천백삼십이만칠천일', '사십삼조오천이백억육천구백십만일'], | |
['이천구백육십조천오백칠십만삼천구백구십', '삼천사백오십조일억이천만육백사십삼'], | |
['사십오억삼천육십만오백구십', '칠십억천이백삼십오만칠천구십이'], | |
['천백십일', '구천오백구십구'], | |
['오억사천', '백십일'], | |
['만오천사백삼십', '십구만삼천오백'], |
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 args = process.argv.slice(2); | |
sumTwoNum(args[0], args[1]) | |
function sumTwoNum(str1, str2) { | |
if (str1.length > str2.length) { | |
[str1, str2] = [str2, str1] | |
} | |
let str = "" |
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
// HOCs | |
function WithCount(Component) { | |
return class withCount extends React.Components { | |
state = { count: 0 } | |
increment = () => { | |
this.setState((state) => ({ count: state.count + 1 })) | |
} | |
decrement = () => { | |
this.setState((state) => ({ count: state.count - 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
import React from 'react' | |
const CountStateContext = React.createContext() | |
const CountDispatchContext = React.createContext() | |
function countReducer(state, action) { | |
switch (action.type) { | |
case 'increment': { | |
return {count: state.count + 1} | |
} | |
case 'decrement': { | |
return {count: state.count - 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
// 1. find | |
const users = [ | |
{ 'user': 'joey', 'age': 32 }, | |
{ 'user': 'ross', 'age': 41 }, | |
{ 'user': 'chandler', 'age': 39 } | |
] | |
// Native | |
users.find(function (o) { return o.age < 40; }) |
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
// 1. Use the Default Iterator from an Array | |
const abcs = ["A", "B", "C"] | |
const createIterator = abcs[Symbol.iterator].bind(abcs) | |
const iterator = createIterator() | |
for (const i of iterator) { | |
console.log(i) | |
} |
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
// 1. Transform an Array into a Single Value using Reduce | |
var data = [15, 3, 20]; | |
var reducer = function(accumulator, item) { | |
return accumulator + item; | |
}; | |
var initialValue = 0; | |
var total = data.reduce(reducer, initialValue); |
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
// 1. Use Concat to Add Values to an Array | |
// Array.prototype.concat(); | |
var people = [ | |
{ | |
name: 'Shane' | |
}, | |
{ | |
name: 'Sally' | |
} | |
]; |
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
// 1. Create a Promise Chain in JavaScript with Promise.prototype.then() | |
const API_URL = "https://starwars.egghead.training/"; | |
const output = document.getElementById("output"); | |
function getFilmTitles(films) { | |
return films | |
.slice() | |
.sort((a, b) => a.episode_id - b.episode_id) | |
.map(film => `${film.episode_id}. ${film.title}`) | |
.join("\n"); |
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
// 1. Use JavaScript (ES6) generators to pause function execution | |
function* createLogger() { | |
console.log('Start') | |
yield | |
console.log('Second block') | |
yield | |
console.log('Third block') | |
yield | |
console.log('End') | |
} |
NewerOlder