TIL 2020.11.16
1 min readNov 17, 2020
underbar & algorithm
Underbar
- similar to underscore.js library
- Goal: Cannot use method of array, set, and map. Only available method is ‘pop’, ‘push’, ‘shift’, ‘sort’ from Array.prototype
shallow copy
deep copy
_.each
- iteratee has access to element or value, index or key, collection
* 배열 arr을 입력받을 경우, iteratee(ele, idx, arr)
* 객체 obj를 입력받을 경우, iteratee(val, key, obj)
- explicitly does not return any value!!!
_.reject
- opposite of filter
- return an array that is false
_.uniq
- return a new array that is not overlap from the values of array
_.pluck
- take key or index that want to find element from object or array
- extract value and save into new array and return that
reduce(arr, iteratee)
iteratee(acc, ele, idx, arr)
- always remember initial value
- with initial value, it becomes accumulator and start iteration with first value from the array
- without initial value, acc will take first value from array and start the function from the second value of array
Algorithm
Make a dummy space
문제
문자열(타입의 알파벳 문자열)을 입력받아 연속되는 문자가 있을 경우, 연속 구간을 반복되는 수와 문자로 조합한 형태로 압축한 문자열을 리턴해야 합니다.
주의 사항
빈 문자열을 입력받은 경우, 빈 문자열을 리턴해야 합니다. 3개 이상 연속되는 문자만 압축합니다.