-
[JS/Asynchronous] Async / Await 다루기Frontend 2019. 8. 10. 23:48
Promise에 이어서 오늘은 Async/Await에 대해서 정리해보려고 한다. Async/Await Async/await은 ES8에서 새롭게 도입되었다. async/await은 promise를 좀 더 이해하기 쉽게 사용하기 위해서 탄생하였다. 그러니까 promise와 전혀 다른 별개의 개념이 아니라 promise를 간단하게 사용하기 위한 문법인 것이다. 그래서 async/await은 기존에 우리가 알던 promise 구문보다 훨씬 간단한 구조로 되어있다. function makeWordPlural (word) { return new Promise((resolve, reject) => { setTimeout(() => { word += "'s "; resolve(word); }, 1000); }); } ..
-
[JS/Asynchronous] Promise / Promise.all(), Promise.race() 정리Frontend 2019. 8. 10. 17:07
저번에 event loop 포스팅에서 언급했듯이 싱글 스레드 언어인 자바스크립트는 한 번에 한 가지 일 밖에 못한다. 그래서 모든 작업을 동기로 처리하면 데이터를 받아와서 화면에 렌더링할 때 데이터 받아오는 작업을 완료하기 전까지는 렌더링을 할 수 없기 때문에 화면이 블록(block)되어 버린다. 그래서 비동기란 것이 생겨났다. 비동기란 일종의 예약 시스템이다. 작업을 동기(Synchronous)로 처리하게 되면 어떤 작업이 끝날 때까지 다음 작업을 진행할 수 없지만 비동기(Asynchronous)로 처리하게 되면 이야기가 달라진다. 어떤 요청을 보내서 응답이 올 때까지 기다려야되는 작업이나 사전에 지정한 시간을 기다려야하는 작업들을 예약을 걸어놓고 지금 당장 처리할 수 있는 작업들을 진행하는 것이다. ..
-
[알고리즘/자바스크립트] 환영 연결 리스트 찾기 (Linked List Cycle)Algorithm 2019. 8. 8. 12:06
Linked List Cycle Generally, we assume that a linked list will terminate in a null next pointer, as follows: A -> B -> C -> D -> E -> null A 'cycle' in a linked list is when traversing the list would result in visiting the same nodes over and over This is caused by pointing a node in the list to another node that already appeared earlier in the list. Example: A -> B -> C ^ | | v E false nodeE.ne..
-
[알고리즘/자바스크립트] 문자열 카운터 (String incrementer)Algorithm 2019. 8. 4. 23:00
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- String incrementer Your job is to write a function which increments a string, to create a new string. If the string already ends with a number, the number should be incremented by 1. If the string does not end with a number. the number 1 should be appended to the new string. foo → foo1 foobar23 → foobar24 foo0042 → foo0043 foo9 → foo10 ..
-
[알고리즘/자바스크립트] Pig Latin 게임 (Simple Pig Latin)Algorithm 2019. 8. 4. 22:32
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- Simple Pig Latin Move the first letter of each word to the end of it, then add "ay" to the end of the word. Leave punctuation marks untouched. pigIt('Pig latin is cool'); // igPay atinlay siay oolcay pigIt('Hello world !'); // elloHay orldway ! 매우 간단한 문제이다. 어떤 문장을 받으면 각 단어의 첫 글자를 그 단어 맨 뒤에 붙이고 'ay'를 덧붙여야한다. ?나 !와 같은 punctuation marks는 제..
-
[알고리즘/자바스크립트] 아나그램 모두 찾기 (Where my anagrams at?)Algorithm 2019. 8. 4. 22:22
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- Where my anagrams at? What is an anagram? Well, two words are anagrams of each other if they both contain the same letters. For example: 'abba' & 'baab' == true 'abba' & 'bbaa' == true 'abba' & 'abbba' == false 'abba' & 'abca' == false Write a function that will find all the anagrams of a word from a list. You will be given two inputs a..
-
[알고리즘/자바스크립트] 반복되지 않는 첫 알파벳 찾기 (First non-repeating character)Algorithm 2019. 8. 4. 22:09
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- First non-repeating character Write a function named first_non_repeating_letter that takes a string input, and returns the first character that is not repeated anywhere in the string. For example, if given the input 'stress', the function should return 't', since the letter t only occurs once in the string, and occurs first in the strin..
-
[알고리즘/자바스크립트] 알파벳 스크램블 (Scramblies)Algorithm 2019. 8. 3. 22:09
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- Scramblies Complete the function scramble(str1, str2) that returns true if a portion of str1 characters can be rearranged to match str2, otherwise returns false. Only lower case letters will be used (a-z). No punctuation or digits will be included. Performance needs to be considered. scramble('rkqodlw', 'world'); // ==> True scramble('c..
-
[알고리즘/자바스크립트] 한 자리수가 될 때까지 곱하기 (Persistent Bugger)Algorithm 2019. 8. 3. 21:40
-해당 문제는 codewars사이트의 level6 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- Persistent Bugger Write a function, persistence, that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit. For example: persistence(39) === 3 // because 3*9 = 27, 2*7 = 14, 1*4=4 // and 4 has only one digit persisten..
-
[JS/Pattern] 대표적인 자바스크립트, 디자인 패턴 정리 (Javascript, Design Pattern)Frontend 2019. 8. 1. 17:59
디자인 패턴이란 무엇일까? 소프트웨어 개발을 하면서 발생하는 다양한 이슈들을 해결하는데 도움을 주는 일종의 증명된 기술들이다. 이미 많은 개발자들이 자바스크립트를 개발하면서 겪은 다양한 경험들을 바탕으로 만들어진 것들이다. 즉, 이런 상황에서는 이런 패턴을 사용하면 좋을거라는 일종의 방향성을 제시해준다. 패턴들은 정확한 해결책을 제공해주는 것이 아니다. 프레임워크나 라이브러리, 패턴 등은 그저 우리가 자바스크립트로 개발하는데 있어서 도움을 주는 도구일 뿐이고 이 패턴들을 어떻게 활용해서 어떤 식으로 개발한 것인지는 순전히 개발자의 역량에 달려있는 것이다. Modules Modules are an integral piece of any robust application's architecture and t..