[Programmers] (Javascript) ํฌ๋ ˆ์ธ ์ธํ˜•๋ฝ‘๊ธฐ
ยท
๐Ÿ’ฏ CodingTest/Programmers
function solution(board, moves) { var answer = 0; var result = []; for(const e of moves) { var floor = e - 1; for(var i =0; i< board.length; i++) { var data = board[i][floor]; if (data !== 0) { if (result.length === 0) { result.push(data); } else { var trg = result.pop(); if (trg === data) { answer += 2 } else { result.push(trg); result.push(data); } } board[i][floor] = 0; break } } } return ans..
[Programmers] (Javascript) ํ‚คํŒจ๋“œ ๋ˆ„๋ฅด๊ธฐ
ยท
๐Ÿ’ฏ CodingTest/Programmers
function solution(numbers, hand) { var answer = ''; var keyPad = new Map([ ['1',[0,0]], ['2',[0,1]], ['3',[0,2]], ['4',[1,0]], ['5',[1,1]], ['6',[1,2]], ['7',[2,0]], ['8',[2,1]], ['9',[2,2]], ['*',[3,0]], ['0',[3,1]], ['#',[3,2]], ]); var lefthand = '*'; var righthand = '#'; for (const num of numbers) { if (num === 1 || num === 4 || num === 7) { answer += ('L'); lefthand = String(num); } else if..
[Programmers] (Javascript) ์ˆซ์ž ๋ฌธ์ž์—ด๊ณผ ์˜๋‹จ์–ด
ยท
๐Ÿ’ฏ CodingTest/Programmers
function solution(s) { var answer = 0; var numMap = new Map([ ['zero', '0'], ['one','1'], ['two','2'], ['three','3'], ['four','4'], ['five','5'], ['six','6'], ['seven','7'], ['eight','8'], ['nine','9'] ]); for(e of numMap) { if (s.includes(e[0])) { var reg = new RegExp(`${e[0]}`,'g'); // ์ •๊ทœ์‹์‚ฌ์šฉํ•˜๋Š”๋ฒ• ์•Œ์•„๋†“๊ธฐ! s = s.replace(reg, e[1]); } } s= parseInt(s); return s; }
[Programmers] (Javascript) ์‹ ๊ทœ์•„์ด๋”” ์ถ”์ฒœ
ยท
๐Ÿ’ฏ CodingTest/Programmers
function solution(new_id) { let answer = ''; const yesMask = '~!@#$%^&*()=+[{]}:?,/'.split(''); // 1๋‹จ๊ณ„ new_id = new_id.toLowerCase(); // 2๋‹จ๊ณ„ new_id = [...new_id].filter(c => !yesMask.includes(c)).join(''); // includes๋Š” ๋ฐฐ์—ด์ด๋‚˜ ๋ฌธ์ž์—ด์— ์‚ฌ์šฉ๊ฐ€๋Šฅ => ๋‚ด๊ฐ€ ์„ ์–ธํ•œ ๋ฐฐ์—ด์ด ์ด์ฐจ์›์€ ์•„๋‹Œ์ง€ ๋ฌธ์ž์—ด์ด ๋งž๋Š”์ง€ ํ™•์ธํ•˜์ž // 3 while (true) { if (!new_id.includes('..')) { break; } new_id = new_id.replace('..', '.'); } // 4 if (new_id[0] == '.') { n..
[Programmers] (Javascript) ๋กœ๋˜์˜ ์ตœ๊ณ  ์ˆœ์œ„์™€ ์ตœ์ € ์ˆœ์œ„
ยท
๐Ÿ’ฏ CodingTest/Programmers
function solution(lottos, win_nums) { let answer = [] let zeroCount = 0 let base = 0 for(num of lottos) { let check = false if (num === 0) { zeroCount += 1 } else { for (let i =0; i { if (score === 6) { return 1; } else if (score..
[Programmers] (Javascript) ์‹ ๊ณ ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ
ยท
๐Ÿ’ฏ CodingTest/Programmers
function solution(id_list, report, k) { let reports = [...new Set(report)].map(a=>{return a.split(' ')}); // Set์œผ๋กœ ๋ณ€ํ™˜ํ•œ๋’ค ํ•ด๋‹น ์›์†Œ๋“ค์„ ๋‹ค์‹œ ๋ฐฐ์—ด๋กœ ๊ฐ€์ ธ์˜ด ์ด๋•Œ ๊ฐ ์›์†Œ์— ๋Œ€ํ•ด split์„ ์ง„ํ–‰ let count = new Map(); for(const e of reports) { count.set(e[1], count.get(e[1]) + 1 || 1) } let note = new Map(); for (const report of reports) { if (count.get(report[1]) >= k) { note.set(report[0], note.get(report[0])+1 || 1) } } let a..
[Programmers] (Javascript) ๋‹คํŠธ๊ฒŒ์ž„
ยท
๐Ÿ’ฏ CodingTest/Programmers
function solution(dartResult) { var bonus = new Map([ ['S',1], ['D',2], ['T',3] ]); var option = new Map([ ['*', 2], ['#', -1], ]); var reg = new RegExp(/\d*[SDT][*#]*/,'g'); var list = dartResult.match(reg); var score = new Map(); var index = 0; for (const data of list) { var num = parseInt(data.match(/\d+/g)); var bo = data.match(/[SDT]/g).toString(); //string์˜ ๊ฒฝ์šฐ toString์„ํ†ตํ•ด arr => string์œผ๋กœ ๋ณ€..