Files
427e7578-d7bf-49c8-aee9-2dd…/dist/server/ssr/assets/poll-R5-eIJ_b.js
yannickschuchmann b936095286 Add implementation
2026-03-08 18:01:28 +00:00

40 lines
891 B
JavaScript

function createPoll(title) {
return {
title,
options: []
};
}
function addOption(poll, text) {
poll.options.push({
id: crypto.randomUUID(),
text,
votes: []
});
}
function hasVoted(poll, optionId, peerId) {
const option = poll.options.find((o) => o.id === optionId);
if (!option) return false;
return option.votes.includes(peerId);
}
function vote(poll, optionId, peerId) {
const option = poll.options.find((o) => o.id === optionId);
if (!option) return;
if (option.votes.includes(peerId)) return;
option.votes.push(peerId);
}
function unvote(poll, optionId, peerId) {
const option = poll.options.find((o) => o.id === optionId);
if (!option) return;
const idx = option.votes.indexOf(peerId);
if (idx !== -1) {
option.votes.splice(idx, 1);
}
}
export {
addOption as a,
createPoll as c,
hasVoted as h,
unvote as u,
vote as v
};