programming study/Algorithm (275) 썸네일형 리스트형 [프로그래머스] 코딩테스트 입문 - JavaScript 풀이 본 게시물은 프로그래머스의 연습 문제 풀이입니다. 저작권은 (주) 그랩에게 있습니다 1. 문자열 정렬하기 (2) const solution = (my_string) => { return my_string.toLowerCase().split('').sort().join(''); } 2. 피자 나눠 먹기 (1) const solution = (n) => { return Math.ceil(n / 7); } 3. 배열 원소의 길이 const solution = (strlist) => { return strlist.map((str) => str.length); } 4. 제곱수 판별하기 const solution = (n) => Number.isInteger(Math.sqrt(n))? 1 : 2; 5. 특정 문자 .. [프로그래머스] 코딩테스트 입문 - JavaScript 풀이 본 게시물은 프로그래머스의 연습 문제 풀이입니다. 저작권은 (주) 그랩에게 있습니다 1. 머쓱이보다 키 큰 사람 const solution = (array, height) => { // 키큰 사람 수를 필터링 return array.filter(friendsHeight => friendsHeight > height).length; } 2. 짝수 홀수 개수 const solution = (num_list) => { // reduce로 짝수, 홀수 개수를 담은 배열 return return num_list.reduce((arr, num) => { if (num % 2 === 0) { arr[0] += 1; } else { arr[1] += 1; } return arr; }, [0, 0]) } 3. 배열 뒤집.. [프로그래머스] 코딩테스트 입문 - JavaScript 풀이 본 게시물은 프로그래머스의 연습 문제 풀이입니다. 저작권은 (주) 그랩에게 있습니다 1. 점의 위치 구하기 const solution = (dot) => { const [x, y] = dot; if (x > 0 && y > 0) { return 1; } else if (x 0) { return 2; } else if (x message.length * 2; 4. 삼각형의 완성조건(1) const solution = (sides) => Math.max(...sides) * 2 acc +cur)? 1 : 2; 5. 최댓값 만들기 const solution = (numbers) => { numbers.sort((a, b) => b - a); return numbers[0] * numbers[1]; } 6. 문.. [프로그래머스] 코딩테스트 입문 - JavaScript 풀이 본 게시물은 프로그래머스의 연습 문제 풀이입니다. 저작권은 (주) 그랩에게 있습니다 1. 각도기 const solution = (angle) => { if (angle array.filter(number => number === n).length; 4. 중앙값 구하기 const solution = (array) => array.sort((a, b) => a - b)[parseInt(array.length / 2)]; 5. 자릿수 더하기 const solution = (n) => n.toString().split('').reduce((acc, cur) => acc + Number(cur), 0); 6. 피자 나눠 먹기(3) const solution = (slice, n) => Math.ceil(n / s.. [프로그래머스] 코딩테스트 입문 - JavaScript 풀이 본 게시물은 프로그래머스의 연습 문제 풀이입니다. 저작권은 (주) 그랩에게 있습니다 1. 문자열 안에 문자열 const solution = (str1, str2) => str1.includes(str2) ? 1 : 2; 2. 짝수의 합 const solution = (n) => { let answer = 0; for (let i = 2; i numbers.reduce((acc, cur) => acc + cur, 0) /numbers.length; const solution = (num1, num2) => num1 - num2; 2. 두 수의 곱 const solution = (num1, num2) => num1 * num2; 3. 두 수의 합 const solution = (num1, num2) => n.. [프로그래머스] 7의 개수 - JavaScript 풀이 본 게시물은 프로그래머스의 연습 문제 풀이입니다. 저작권은 (주) 그랩에게 있습니다 자바스크립트 코드 function solution(array) { let answer = 0; // 주어진 array 순회 array.forEach((number) => { // 순회를하기 위해 문자열로 변환 const numberToString = number.toString(); // 7의 개수를 새기 answer += numberToString.split('').filter(num => num === '7').length; }) return answer; } Reference 프로그래머스 [프로그래머스] 가장 먼 노드 - JavaScript 풀이 본 게시물은 프로그래머스의 연습 문제 풀이입니다. 저작권은 (주) 그랩에게 있습니다 자바스크립트 코드 const solution = (common) => { // 등차수열인지 등비수열인지 판별 const first = common[0]; const second = common[1]; const third = common[2]; const difference1 = second - first; const difference2 = third - second; // 다음에 올 수 let nextNumber = common[common.length - 1]; // 두 차이가 같으면 등차수열 if (difference1 === difference2) { const difference = difference1; ne.. [프로그래머스] 코딩테스트 입문 - JavaScript 풀이 본 게시물은 프로그래머스의 연습 문제 풀이입니다. 저작권은 (주) 그랩에게 있습니다 프로그래머스의 Lv.0 문제 풀이. 문제를 읽고 바로 풀 수 있을 정도로 매우 쉬운난이도로 화살표 함수를 사용하여 최대한 간략하게 풀이. 1. 두 수의 차 const solution = (num1, num2) => num1 - num2; 2. 두 수의 곱 const solution = (num1, num2) => num1 * num2; 3. 두 수의 합 const solution = (num1, num2) => num1 + num2; 4. 숫자 비교하기 const solution = (num1, num2) => num1 === num2 ? 1 : -1; 5. 몫 구하기 const solution = (num1, num2).. 이전 1 ··· 3 4 5 6 7 8 9 ··· 35 다음