[프로그래머스 | 자바스크립트] 자릿수 더하기
솔루션 const solution = (n) => { const answer = [...("" + n)].map((v) => +v).reduce((x, y) => x + y, 0); console.log(answer); return answer; }; 솔루션 const solution2 = (n) => { const answer = n .toString() .split("") .reduce((x, y) => x + Number(y), 0); console.log(answer); return answer; };
- 프로그래머스(Javascript)/Level 0
- · 2023. 2. 5.
[프로그래머스 | 자바스크립트] 문자열안에 문자열
솔루션 const solution = (str1, str2) => { const answer = str1.includes(str2) ? 1 : 2; console.log(answer); return answer; }; 솔루션 const solution2 = (str1, str2) => { const answer = str1.split(str2).length > 1 ? 1 : 2; console.log(answer); return answer; };
- 프로그래머스(Javascript)/Level 0
- · 2023. 2. 5.
[프로그래머스 | 자바스크립트] 제곱수 판별하기
솔루션 const solution = (n) => { const answer = Number.isInteger(Math.sqrt(n)) ? 1 : 2; console.log(answer); return answer; };
- 프로그래머스(Javascript)/Level 0
- · 2023. 2. 5.
[프로그래머스 | 자바스크립트] 세균 증식
솔루션 const solution = (n, t) => { const answer = n * 2 ** t; console.log(answer); return answer; }; 솔루션 const solution2 = (n, t) => { console.log(n 0) { n *= 2; } console.log(n); return n; }; 솔루션 const solution4 = (n, t) => { const answer = n * Math.pow(2, t); console.log(answer); return answer; };
- 프로그래머스(Javascript)/Level 0
- · 2023. 2. 5.