사랑하애오
[프로그래머스 | 자바스크립트] 숨어있는 숫자의 덧셈(2)

솔루션 const solution = (my_string) => { const nums = my_string.match(/[0-9]+/g); const answer = nums ? nums.map((num) => +num).reduce((a, c) => a + c, 0) : 0; console.log(answer); return answer; }; 솔루션 function solution(my_string) { const answer = my_string.split(/\D+/).reduce((acc, cur) => acc + Number(cur), 0); console.log(answer); return answer; } 솔루션 function solution(n) { let answer = "" for(..

[프로그래머스 | 자바스크립트] 안전지대

솔루션 function solution(board) { const isBombNearby = (r, c) => { const nearby = [ [-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1], ]; const isInBoard = (r, c) => r >= 0 && r = 0 && c isInBoard(r + dR, c + dC) && board[r + dR][c + dC] === 1 ); }; let answer = 0; for (let r = 0; r < board.length; r++) { for ..

[프로그래머스 | 자바스크립트] 삼각형의 완성조건(2)

솔루션 function solution(sides) { const min = Math.min(...sides); const max1 = Math.max(...sides); const max2 = min + max1 - 1; return max2 - (max1 - min); } 솔루션 function solution(sides) { return Math.min(...sides) * 2 - 1; }

[프로그래머스 | 자바스크립트] 외계어 사전

솔루션 const solution = (spell, dic) => { const sort = (str) => [...str].sort((a, b) => (a sort(dic) === sort(spell.join(""))) ? 1 : 2; console.log(answer); return answer; }; solution(["p", "o", "s"], ["sod", "eocd", "qixm", "adio", "soo"]); solution(["z", "d", "x"], ["def", "dww", "dzx", "loveaw"]); solution(["s", "o", "m", "d..

[프로그래머스 | 자바스크립트] 저주의 숫자 3

솔루션 const solution = (n) => { let num = 0; let count = 0; while (count < n) { num += 1; if (!("" + num).includes("3") && num % 3 !== 0) count += 1; } console.log(num); return num; };

[프로그래머스 | 자바스크립트] 평행

솔루션 const solution = (dots) => { const getInclination = ([[x1, y1], [x2, y2]]) => x2 !== x1 ? (y2 - y1) / (x2 - x1) : Infinity; const isParallel = (line1, line2) => getInclination(line1) === getInclination(line2); const answer = dots.some((dot) => { const line1 = [dots[0], dot]; const line2 = dots.filter((dot) => !line1.includes(dot)); return isParallel(line1, line2); }) ? 1 : 0; console.log(ans..

[프로그래머스 | 자바스크립트] 겹치는 선분의 길이

솔루션 const solution = (lines) => { const answer = lines.reduce((a, [x, y]) => { for (let i = Math.min(x, y) + 1; i v > 1).length); return Object.values(answer).filter((v) => v > 1).length; }; 솔루션 const solution = (lines) => { let line = new Array(200).fill(0); lines.forEach(([a, b]) => { for (; a (c > 1 ? a + 1 : a), 0); console...

[프로그래머스 | 자바스크립트] 유한소수 판별하기

솔루션 const solution = (a, b) => { const getGCD = (a, b) => { let gcd = 1; for (let i = 1; i { let pFactors = []; for (let i = 2; i 2) pFactors = [...pFactors, num]; return pFactors; }; const answer = getPrimeFactors(b / getGCD(a, b)).find( (n) => n !== 2 && n !== 5 ) ? 2 : 1; console.log(answer); return answer; };