HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
📝
프론트엔드 스쿨 교안(1기)
/
📝
(코테준비) 자료구조 및 알고리즘
/
☝
JS 100제 - 1권
/
🔥
문제37
/
✔️
답안
✔️

답안

const array = prompt('이름을 입력해주세요.').split(' '); let result = {}; let winner = ""; for(let index in array){ let val = array[index]; result[val] = result[val] === undefined ? 1 : result[val] = result[val] + 1; } winner = Object.keys(result).reduce(function(a, b){ return result[a] > result[b] ? a : b }); console.log(`${winner}(이)가 총 ${result[winner]}표로 반장이 되었습니다.`);