Hyebin‘s blog
[Codewars/JS] RGB To Hex Conversion
Algorithm/Codewars 2022. 1. 13. 17:44

The rgb function is incomplete. Complete it so that passing in RGB decimal values will result in a hexadecimal representation being returned. Valid decimal values for RGB are 0 - 255. Any values that fall out of that range must be rounded to the closest valid value. Note: Your answer should always be 6 characters long, the shorthand with 3 will not work here. The following are examples of expect..

[Codewars/JS] Two to One
Algorithm/Codewars 2022. 1. 13. 16:53

Details Take 2 strings s1 and s2 including only letters from ato z. Return a new sorted string, the longest possible, containing distinct letters - each taken only once - coming from s1 or s2. Examples: a = "xyaabbbccccdefww" b = "xxxxyyyyabklmopq" longest(a, b) -> "abcdefklmopqwxy" a = "abcdefghijklmnopqrstuvwxyz" longest(a, a) -> "abcdefghijklmnopqrstuvwxyz" function longest(s1, s2) { const st..

[Codewars/JS] Count the number of Duplicates
Algorithm/Codewars 2022. 1. 12. 17:09

Count the number of Duplicates Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits. Example "abcde" -> 0 # no characters repeats more than once "aabbcde" -> 2 # 'a' and 'b' "aabBcde..

[codewars/JS] Sort the odd
Algorithm/Codewars 2022. 1. 12. 15:05

Task You will be given an array of numbers. You have to sort the odd numbers in ascending order while leaving the even numbers at their original positions. Examples [7, 1] => [1, 7] [5, 8, 6, 3, 4] => [3, 8, 6, 5, 4] [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] => [1, 8, 3, 6, 5, 4, 7, 2, 9, 0] function sortArray(array) { const result = array.filter((a)=> a%2 !== 0) result.sort(function(a,b){ return a-b }); c..

[codewars/JS] Growth of a Population
Algorithm/Codewars 2022. 1. 12. 01:39

Instructions In a small town the population is p0 = 1000 at the beginning of a year. The population regularly increases by 2 percent per year and moreover 50 new inhabitants per year come to live in the town. How many years does the town need to see its population greater or equal to p = 1200 inhabitants? At the end of the first year there will be: 1000 + 1000 * 0.02 + 50 => 1070 inhabitants At ..

[JavaScript] sort() 함수
Front-end/JavaScript 2022. 1. 11. 22:29

sort() 함수? 정렬 순서를 정의하는 함수. 이 값이 생략되면, 배열의 element들은 문자열로 취급되어, 유니코드 값 순서대로 정렬됩니다. 리턴하는 값이 -1인경우, a가 b보다 앞에 오도록 정렬하고, 리턴하는 값이 1인 경우, b가 a보다 앞에 오도록 정렬합니다. 만약 0을 리턴하면, a와 b의 순서를 변경하지 않습니다. 배열의 숫자들을 유니코드 순서가 아닌, 숫자 크기 순서대로 정렬하기 위해서 sort() 함수의 파라미터로 함수를 정의해야한다. 두 숫자의 차가 양수값이냐, 음수값이냐를 이용하여 두 숫자의 차이를 리턴하는 함수를 sort() 함수의 파라미터로 전달 숫자를 오름차순으로 정렬하는 예제를 위와 같이 단순화 배열의 오름 차순 방법 1) arr.sort(function(a, b) { if..

[codewars/JS] Sum of two lowest positive integers
Algorithm/Codewars 2022. 1. 11. 22:21

Description: Create a function that returns the sum of the two lowest positive numbers given an array of minimum 4 positive integers. No floats or non-positive integers will be passed. For example, when an array is passed like [19, 5, 42, 2, 77], the output should be 7. [10, 343445353, 3453445, 3453545353453] should return 3453455. function sumTwoSmallestNumbers(numbers) { const sortArray = numb..

[React] 코딩애플 blog-part3-8 (성능 잡기 - lazy loading / React devtools / memo)
Front-end/React 2022. 1. 11. 17:16

기능 구현 다음에 가장 중요한 것은 바로 성능향상과 유지관리이다! 리액트도 컴포넌트의 로딩속도 등 향상시킬 수 있는 방법이 존재한다 1. 함수나 오브젝트는 변수에 담아 쓰는게 좋다! 부제 : 익명함수/익명object 안쓰기 =메모리공간을 아낄 수 있는 JS 코딩 관습 function Cart(){ return ( ) } 콜백함수나 오브젝트를 써넣지 말고 var 스타일 = {color : 'red'}; function Cart(){ return ( ) } 컴포넌트 바깥에 있는 변수에 저장해서 사용하자! 강의에선 function Cart 안에 넣는데 그거 아니고 바깥에 넣자! 왜냐면 컴포넌트가 재렌더링될 때 변수에 저장되지 않은 이름없는 object, function 류의 자료형들은 매번 새로운 메모리 영역..

검색 태그