목록알고리즘 풀이 모음 (50)
HYEWON JUNG의 개발일지
문제설명 자연수 n이 매개변수로 주어집니다. n을 x로 나눈 나머지가 1이 되도록 하는 가장 작은 자연수 x를 return 하도록 solution 함수를 완성해주세요. 답이 항상 존재함은 증명될 수 있습니다. 제한사항 3 ≤ n ≤ 1,000,000 입출력 내코드 function solution(n) { for(let i = 1; i < n ; i++){ if(n%i === 1){ return i } } }
문제설명 두 정수 a, b가 주어졌을 때 a와 b 사이에 속한 모든 정수의 합을 리턴하는 함수, solution을 완성하세요. 예를 들어 a = 3, b = 5인 경우, 3 + 4 + 5 = 12이므로 12를 리턴합니다 제한사항 a와 b가 같은 경우는 둘 중 아무 수나 리턴하세요. a와 b는 -10,000,000 이상 10,000,000 이하인 정수입니다. a와 b의 대소관계는 정해져있지 않습니다. 입출력 내코드 function solution(a, b) { let answer = 0; for(let i = Math.min(a, b); i
문제설명 정수를 담고 있는 배열 arr의 평균값을 return하는 함수, solution을 완성해보세요. 제한사항 arr은 길이 1 이상, 100 이하인 배열입니다. arr의 원소는 -10,000 이상 10,000 이하인 정수입니다. 입출력 내코드 function solution(arr) { var answer = 0; for(let i= 0; ia+b , 0)/arr.length }
문제설명 정수 n을 입력받아 n의 약수를 모두 더한 값을 리턴하는 함수, solution을 완성해주세요. 제한사항 n은 0 이상 3000이하인 정수입니다. 입출력 내코드 function solution(n) { var answer =0 for(let i = 1 ; i
문제설명 문자열 str1, str2가 매개변수로 주어집니다. str1 안에 str2가 있다면 1을 없다면 2를 return하도록 solution 함수를 완성해주세요. 제한사항 1 ≤ str1의 길이 ≤ 100 1 ≤ str2의 길이 ≤ 100 문자열은 알파벳 대문자, 소문자, 숫자로 구성되어 있습니다. 입출력 내코드 function solution(str1, str2) { var answer = str1.includes(str2)? 1: 2 return answer; }
문제설명 머쓱이네 피자가게는 피자를 일곱 조각으로 잘라 줍니다. 피자를 나눠먹을 사람의 수 n이 주어질 때, 모든 사람이 피자를 한 조각 이상 먹기 위해 필요한 피자의 수를 return 하는 solution 함수를 완성해보세요. 제한사항 1 ≤ n ≤ 100 입출력 내코드 function solution(n) { var answer = Math.ceil(n/7); return answer; } 2023.11.26 - [JavaScript] - Math 메소드 살펴보기!Math.abs() Math.ceil() Math.floor() Math.round()Math.trunc()Math.max()Math.min()Math.pow()Math.sign() Math.sign() ", mathAbs(2, 5));" ..