본문 바로가기

js26

Abbreviate a Two Word Name Description: Write a function to convert a name into initials. This kata strictly takes two words with one space in between them. The output should be two capital letters with a dot separating them. It should look like this: Sam Harris => S.H patrick feeney => P.F solution: 1. Change the name to all uppercase letters. 2. Separate strings based on space and put them in an array. 3. Put the first .. 2022. 3. 6.
JavaScript _ 스프레드 연산자로 배열 합치기 자바스크립트에는 스프레드 연산자라는 것이 있습니다. 형태는 '...arr' 이렇게 생겼습니다. 보통 배열을 합치거나 복사할 때 사용가능하고 함수에도 사용할 수 있습니다. 사용법은 다음과 같습니다. 1. 배열을 합칠 때 let a = [1,2,3,4,5]; let b = [5,5,5,5,5]; let c = [...b, ...a]; console.log(c) >>> [ 5, 5, 5, 5, 5, 1, 2, 3, 4, 5 ] 스프레드 연산자 '점점점'과 배열 변수명을 요소로 넣으면 됩니다. 2. 배열을 복사 할 때 let a = [1,2,3,4,5]; let d = [...a] console.log(d) >>> [ 1, 2, 3, 4, 5 ] 위와 동일한 방법으로 해당 배열을 복사할 수도 있습니다. 이렇게 .. 2022. 3. 5.
JavaScript _ 'for문'으로 배열의 합을 구하는 방법 자바스크립트의 경우 배열의 합을 구하는 간단한 내장함수가 없는 것 같습니다. (파이썬 최고..) 라이브러리를 설치하거나 for문 혹은 reduce함수를 사용해야하는데 이번 글에서 for문으로 배열 합을 구하는 함수를 만들어 보겠습니다. 코드부터 볼까요? let a = [1,2,3,4,5]; function sum(a){ let sum = 0; for (let i of a){ sum += i; }; return sum; }; console.log(sum(a)) >>> 15 1. 함수 sum은 배열을 인자로 받습니다. 2. 배열로부터 요소를 뽑아 sum이라는 변수에 반복하여 더합니다. 3. sum 변수를 반환합니다. 이처럼 함수를 미리 작성해두면 Python의 sum() 처럼 배열 합계를 구하는데 사용할 수.. 2022. 3. 5.
Equal Sides Of An Array Description: You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, return -1. For example: Let's say you are given the array {1,2,3,4,3,2,1}: Your function will return the index 3, because at the 3rd p.. 2022. 3. 5.
js로 숫자 맞추기 게임을 만들어 배포하였다. 일주일 동안 기업과제에 묶여있어서 문제를 해결하느라 블로그를 소홀히 하였다. 기복없는 개발자가 되기위해선 꾸준한 기록이 필요하고 꾸준한 기록은 기록 자체를 더 단순하고 간결하게 만들어야 가능하다고 생각한다. 앞으로 이를 위해 계속해서 블로그 포스팅 방법을 수정 보완할 예정이다. 오늘 한 것 파이썬 딕셔너리를 능숙하게 사용하지 못하는 것 같아서 이를 보완하고자 문법을 정리하여 포스팅했다. 강의를 참고하여 js로 '숫자 맞추기 게임'을 만들어 배포하였다. 배포 링크 2022.03.04 - [Dev/Language] - Python 딕셔너리 추가, 삭제 메서드 정리 2022.03.04 - [Dev/Language] - Python 딕셔너리 가져오기 메서드 정리 성장한 점 파이썬 딕셔너리에 대해 몰랐던 메서드를.. 2022. 3. 4.
Is this a triangle? Description: Implement a function that accepts 3 integer values a, b, c. The function should return true if a triangle can be built with the sides of given length and false in any other case. (In this case, all triangles must have surface greater than 0 to be accepted). Solution: 1. Sort a, b, c in ascending order. 2. Compare the last number (largest number) with the sum of the remaining two num.. 2022. 3. 4.