function setSortAndFliter(arr, arr2) { return arr.sort((a, b) => a - b).filter((v) => !arr2.includes(v)); } function solution(n, lost, reserve) { const noPeClothesStudent = setSortAndFliter(lost, reserve); const extraPeClothesStudent = setSortAndFliter(reserve, lost); for (const el of noPeClothesStudent) { const extraUniformidx = extraPeClothesStudent.findIndex( (value) => value === el - 1 || va..
์๊ณ ๋ฆฌ์ฆ & ๋ฌธ์ ํ์ด/Programmers-1
ํ์ด ๐๐ปโ๏ธ function solution(participant, completion) { participant.sort(); completion.sort(); for (let i = 0; i
ํ์ด1 ๐๐ปโ๏ธ //ํ์ด 1 function solution(nums) { const numberOfAllCases = getCombinations(nums, 3).map((innerArr) => innerArr.reduce((acc, cur) => acc + cur, 0) ); let result = 0; numberOfAllCases.map((v) => { if (primeNumber(v)) result++; }); return result; } const primeNumber = (x) => { for (let i = 2; i { const result = []; if (arrLength === 1) return arr.map((el) => [el]); arr.map((item, idx, this..
ํ์ด ๐๐ปโ๏ธ function solution(answer) { const result = []; const personOne = [1, 2, 3, 4, 5]; const personTwo = [2, 1, 2, 3, 2, 4, 2, 5]; const personThree = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]; const answerOne = answer.filter((v, i) => v === personOne[i % 5]).length; const answerTwo = answer.filter((v, i) => v === personTwo[i % 8]).length; const answerThree = answer.filter((v, i) => v === personThree[i..
ํ์ด๐๐ปโ๏ธ function solution(nums) { const numsSetSize = new Set(nums).size; const numsHalfCount = nums.length / 2; return numsSetSize > numsHalfCount ? numsHalfCount : numsSetSize; } /* (ํ์ด) ์ฃผ์ด์ง ๋ฐฐ์ด์ Set ๊ฐ์ฒด๋ก ๋ณํํ์ฌ ์ค๋ณต์ ์ ๊ฑฐํด์ฃผ๊ณ numsSetSize๊ฐ nums์ ๊ฐ์ / 2 ๋ณด๋ค ๋ง์ผ๋ฉด nums.length์ ์ ๋ฐ์ธ numsHalfCount๋ฅผ ๋ฆฌํดํด์ฃผ๊ณ ์๋๋ฉด numsSetSize๋ฅผ ๋ฆฌํดํด์ค๋ค. ์์งํ ๋ ํ๋ ์ผ์ด์ค๊ฐ ์๋ค๋๊ฐ ํด์ ์คํจํ ์ค ์์๋๋ฐ ํต๊ณผ๋๋ค. ํ
์คํธ์ ์ด๋ฆ์ ๋ณด๋ ํด์์ธ๋ฐ ๊ด๋ จ ์๋ฃ๋ฅผ ์ฐพ์๋ณด๋ ํด์๋ ์์์ ๊ธธ์ด์ ๋ฐ์ดํฐ๋ฅผ..
ํ์ด ๐๐ปโ๏ธ function solution(sizes) { const maxSizes = Math.max(...sizes.flat()); let secondMaxSizes = 0; for (el of sizes) { if (el[0] > el[1]) { if (el[1] > secondMaxSizes) { secondMaxSizes = el[1]; } } else { if (el[0] > secondMaxSizes) { secondMaxSizes = el[0]; } } } return maxSizes * secondMaxSizes; } ๋ถํ์ํ if ๋ฌธ์ด ๋ง์๋ณด์ธ๋ค.. ํผ๋๋ฐฑ function solution(sizes) { const maxSize = Math.max(...sizes.flat());..
ํ์ด ๐๐ปโ๏ธ function solution(s) { const strArr = s.split(" "); let result = ""; for (let i = 0; i < strArr.length; i++) { for (let j = 0; j < strArr[i].length; j++) { result += !(j % 2) ? strArr[i][j].toUpperCase() : strArr[i][j].toLowerCase(); } if (i < strArr.length - 1) { result += " "; } } return result; } /* (ํ์ด) ํ๋ ์ผ์ด์ค ํด๊ฒฐ์ ์ ๋ง ๋ง์ ์๊ฐ์ ๋ฒ๋ ธ๋ค.. 2์ค for๋ฌธ์ผ๋ก split์ผ๋ก ๋๋ ์ค strArr ๋ฐฐ์ด์์์ ๊ฐ์๋งํผ ๋๋ ค์ฃผ๊ณ ๋ด๋ถ for๋ฌธ์์..
ํ์ด ๐๐ปโ๏ธ function solution(arr) { return arr.filter((el, idx) => el !== arr[idx + 1]); } ํด๋น ๋ฌธ์ ๋ ์คํ/ํ ์๋ฃ๊ตฌ์กฐ๋ฅผ ์ด์ฉํด ํธ๋ ํ์ด์๋๋ฐ ํ์ด์์ฒด๋ ์ข์ง๋ง ๋ฌธ์ ์๋์ ๋ง์ง์๋ค. ์๋์ ๋ง๋ ํ์ด์ ๋ํด ์์๋ณด์. ๋ฌธ์ ์๋์ ๋ง๋ ํ์ด function solution(arr) { const result = []; for (const el of arr) { const lastElement = result[result.length - 1]; if (lastElement !== el) result.push(el); } return result; } ์คํฐ๋ ๋ฆฌ๋๋์ด ์ฌ๋ ค์ฃผ์ ํ์ด. ์คํ ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง ํ์ด๋ค. ๋๋ ์์๋ฅผ ๋นผ๊ณ ๋ฃ๋ ์์
..