Last active
August 3, 2020 06:40
-
-
Save leegeunhyeok/ae08d9d4af37192f8942fd7b930bffcc to your computer and use it in GitHub Desktop.
[출간기념 이벤트] SNS 앱으로 배우는 프로그레시브 웹 앱 - 페이스북 생활코딩 추첨
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const PICK = 5; // 추첨 인원 | |
const picked = {}; // 중복 추첨 방지 확인용 객체 | |
const commentCount = $0.childElementCount // 전체 댓글 수 | |
const users = Array.from($0.children).map((comment) => comment.querySelector('[aria-label="Comment"]')); | |
for (let i = 0; i < PICK; i++) { | |
let idx = Math.floor(Math.random() * commentCount); | |
while (picked[idx]) { | |
idx = Math.floor(Math.random() * commentCount); | |
} | |
picked[idx] = true; | |
console.log(`#${i + 1}: ${users[idx].querySelector('img').getAttribute('alt')}`, users[idx]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment