diff --git a/prob1.js b/prob1.js index 2eed222..2e61324 100644 --- a/prob1.js +++ b/prob1.js @@ -1,7 +1,16 @@ //1. 함수 로직 작성 문제 - +let num = 0; +let total = 0; +let first = 0; function solution(num, total) { let answer = []; - + first = Math.ceil(total / num) - Math.floor(num / 2); + for(let i = 0; i < num; i++){ + answer[i] = first++; + } return answer; } + +console.log(solution(3, 12)); +console.log(solution(4, 14)); +console.log(solution(5, 5)); \ No newline at end of file diff --git a/prob2.js b/prob2.js index 43114a4..88fb850 100644 --- a/prob2.js +++ b/prob2.js @@ -1,6 +1,14 @@ //2. map활용 문제 const numbers = [1, 2, 3, 4, 5]; - let answer; +answer = numbers.map(function(element){ + if (element % 2 == 1){ + return "홀수"; + } + else{ + return "짝수"; + } +}); + console.log(answer); diff --git a/prob3.js b/prob3.js index b1eacf7..ab26a37 100644 --- a/prob3.js +++ b/prob3.js @@ -6,14 +6,32 @@ let likelion = [ ]; // 1번 문제 코드작성 +let result1 = likelion; +for (let i = 0; i < result1.length - 1; i++){ + for (let j = 0; j < result1.length - 1 - i; j++){ + if (result1[j].age > result1[j+1].age){ + [result1[j], result1[j+1]] = [result1[j+1], result1[j]]; + } + } +} +console.log("나이순:", result1); + // 2번 문제 코드작성 let result2 = []; - -console.log(result2); +for (let i = 0; i < likelion.length; i++){ + if (likelion[i].age > 24){ + result2.push(likelion[i]); + } +} +console.log("24세 이상 팀원:", result2); // 3번 문제 코드작성 let targetName = "전수빈"; let result3 = null; - -console.log(result3); +for (let i = 0; i < likelion.length; i++){ + if (likelion[i].name === targetName){ + result3 = likelion[i].part; + } +} +console.log(targetName, "님 Part:", result3);