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

솔루션 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; };

[프로그래머스 | 자바스크립트] 등수 매기기

솔루션 const solution = (score) => { const avgs = score.map(([a, b]) => (a + b) / 2); const avgRank = [...avgs] .sort((a, b) => b - a) .map((avg, i) => ({ avg, rank: i + 1 })) .map((a, i, arr) => i > 0 && a.avg === arr[i - 1].avg ? { ...a, rank: arr[i - 1].rank } : a ); console.log(avgRank); const answer = avgs.map( (_avg) => avgRank.find(({ avg }) => _avg === avg).rank ); console.log(answer); retu..

[프로그래머스 | 자바스크립트] 로그인 성공?

솔루션 const solution = (id_pw, db) => { const [id, pw] = id_pw; const answer = db.find(([_id, _pw]) => _id === id && _pw === pw) ? "login" : !db.find(([_id]) => _id === id) ? "fail" : "wrong pw"; console.log(answer); return answer; }; 솔루션 const solution = (id_pw, db) => { const [id, pw] = id_pw; const map = new Map(db); const answer = map.has(id) ? map.get(id) === pw ? "login" : "wrong pw" : "fail..

[프로그래머스 | 자바스크립트] 치킨 쿠폰

솔루션 const order = (chicken) => { if (chicken { const answer = order(chicken); console.log(answer); return answer; }; 솔루션 const solution = (chicken) => { let answer = 0; let coupon = chicken; while (coupon >= 10) { answer = answer + parseInt(coupon / 10); co..

[프로그래머스 | 자바스크립트] 특이한 정렬

솔루션 const solution = (numlist, n) => { const answer = numlist.sort((a, b) => { const [x, y] = [Math.abs(a - n), Math.abs(b - n)]; if (x === y) return b - a; return x - y; }); console.log("answer ", answer); return answer; };

[프로그래머스 | 자바스크립트] 이진수 더하기

솔루션 const solution = (bin1, bin2) => { const answer = (parseInt(bin1, 2) + parseInt(bin2, 2)).toString(2); console.log(answer); return answer; }; 솔루션 const solution = (bin1, bin2) => { let temp = Number(bin1) + Number(bin2); temp = [...temp.toString()].reverse().map((v) => +v); for (let i = temp.length; i < 11; i++) { temp.push(0); } for (let i = 0; i < temp.length; i++) { if (temp[i] === 2) { t..

[프로그래머스 | 자바스크립트] A로 B만들기

솔루션 const solution = (before, after) => { const sort = (str) => [...str].sort((a, b) => (a { const answer = before.split("").sort().join("") === after.split("").sort().join("") ? 1 : 0; console.log(answer); return answer; };