솔루션 const solution = (array, n) => { const minDiff = Math.min(...array.map((v) => Math.abs(v - n))); console.log(minDiff); const answer = array .sort((a, b) => a - b) .find((a) => Math.abs(a - n) === minDiff); console.log(answer); return answer; }; Math 메서드의 min(최솟값)과 abs(절댓값)을 이용
솔루션 const solution = (order) => { const str = [...("" + order)].filter( (v) => v === "3" || v === "6" || v === "9" ); const answer = str.length; console.log(answer); return answer; }; 솔루션 const solution = (order) => { const answer = [...order.toString().matchAll(/[3|6|9]/g)].length; console.log(answer); return answer; }; 정규식을 이용한 풀이 솔루션 const solution = (order) => { const set = new Set([3, 6, 9]..
솔루션 const solution = (cipher, code) => { const str = [...cipher]; const answer = str.reduce( (a, c, i) => ((i + 1) % code === 0 ? a + c : a), "" ); console.log(answer); return answer; }; 솔루션 const solution = (cipher, code) => { const answer = []; for (let i = code - 1; i < cipher.length; i += code) { answer.push(cipher[i]); } console.log(answer.join("")); return answer.join(""); }; 솔루션 const sol..
솔루션 const solution = (my_string) => { const str = [...my_string]; console.log(str); const answer = str .map((v) => (v === v.toUpperCase() ? v.toLowerCase() : v.toUpperCase())) .join(""); console.log(answer); return answer; }; 솔루션 const solution = (my_string) => { let answer = ""; for (const str of my_string) { answer += str === str.toLowerCase() ? str.toUpperCase() : str.toLowerCase(); } console..
솔루션 const num = [ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", ]; const solution = (numbers) => { for (let i = 0; i < num.length; i++) { numbers = numbers.split(num[i]).join(i); } const answer = Number(numbers); console.log(answer); return answer; };
솔루션 const solution = (my_string, num1, num2) => { const str = [...my_string]; console.log(str); [str[num1], str[num2]] = [str[num2], str[num1]]; const answer = str.join(""); console.log(answer); return answer; }; 솔루션 const solution = (my_string, num1, num2) => { const str = []; let answer = ""; for (let i = 0; i < my_string.length; i++) { if (i === num1 || i === num2) { str.push(my_string[i]); }..
솔루션 const solution = (s) => { const count = [...s].reduce( (a, c) => (a[c] ? { ...a, [c]: a[c] + 1 } : { ...a, [c]: 1 }), {} ); console.log(count); const answer = Object.keys(count) .filter((key) => count[key] === 1) .sort((a, b) => (a b ? 1 : 0)) .join(""); console.log(answer); return answer; }; 솔루션 const solution = (s) => { let answer = []; for (const v of s) { if (s.indexOf(v) ..
솔루션 function solution(n) { let answer = []; for (let i = 1; i a - b); } 솔루션 function solution2(n) { const answer = Array(n) .fill(0) .map((v, i) => v + i + 1) .filter((v) => n % v === 0); consol..