Skip to content

Commit

Permalink
remove unnecessary whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffrey-wu committed Aug 12, 2022
1 parent 9fc4611 commit aba5893
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Player.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Player {
constructor (userId) {
constructor(userId) {
this.userId = userId;
this.username = '';
this.powers = 0;
Expand Down
16 changes: 8 additions & 8 deletions Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Room {

this.tossup = {};
this.questionNumber = 0;
this.questionProgress = 0, // 0 = not started, 1 = reading, 2 = answer reveale;
this.questionProgress = 0; // 0 = not started, 1 = reading, 2 = answer revealed
this.wordIndex = 0;

this.difficulties = [4, 5];
Expand Down Expand Up @@ -120,7 +120,7 @@ class Room {
this.players[userId].clearStats();
this.sendSocketMessage(message);
}

if (type === 'difficulties') {
this.difficulties = message.value;
this.sendSocketMessage(message);
Expand Down Expand Up @@ -154,23 +154,23 @@ class Room {
if (type === 'pause') {
this.pause(userId);
}

if (type === 'reading-speed') {
this.readingSpeed = message.value;
this.sendSocketMessage(message);
}

if (type === 'set-name') {
this.setName = message.value;
this.questionNumber = -1;
this.sendSocketMessage(message);
}

if (type === 'toggle-multiple-buzzes') {
this.allowMultipleBuzzes = message.allowMultipleBuzzes;
this.sendSocketMessage(message);
}

if (type === 'toggle-select-by-difficulty') {
this.selectByDifficulty = message.selectByDifficulty;
this.setName = message.setName;
Expand All @@ -182,7 +182,7 @@ class Room {
this.public = message.public;
this.sendSocketMessage(message);
}

if (type === 'update-categories') {
this.validCategories = message.categories;
this.validSubcategories = message.subcategories;
Expand Down Expand Up @@ -265,7 +265,7 @@ class Room {
};
}

deletePlayer(userId) {
deletePlayer(userId) {
this.sendSocketMessage({
type: 'leave',
userId: userId,
Expand Down
28 changes: 14 additions & 14 deletions quizbowl.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,27 @@ function checkAnswer(answerline, givenAnswer, isFormattedAnswerline) {
const parseAnswerline = (answerline) => {
const removeParentheses = (string) => {
string = string.replace(/\([^\)]*\)/g, '');

return string;
}

const splitMainAnswer = (string) => {
let indexStart = string.indexOf('[');
let indexEnd = string.indexOf(']');
if (indexStart === -1) {
return { mainAnswer: string, subAnswer: '' };
}

let mainAnswer = string.substring(0, indexStart).trim();
let subAnswer = string.substring(indexStart + 1, indexEnd).trim();

return { mainAnswer, subAnswer };
}

const splitIntoPhrases = (string) => {
return string.split(';').map(token => token.trim());
};

const splitIntoAnswers = (phrase) => {
phrase = phrase.toLowerCase();
let directive = 'accept'; // by default, this phrase accepts answers that match to it
Expand All @@ -130,14 +130,14 @@ function checkAnswer(answerline, givenAnswer, isFormattedAnswerline) {
} else if (phrase.startsWith('reject') || phrase.startsWith('do not accept')) {
directive = 'reject';
}

phrase = phrase.replace(/^(or|prompt|prompt on|accept|reject|do not accept or prompt on|do not accept)/, '').trim();

const answers = phrase.split(' or ').map(token => token.trim()).filter(token => token.length > 0);

return { directive, answers };
}

const extractUnderlining = (string) => {
let matches = string.match(/(?<=<u>)[^<]*(?=<\/u>)/g);
if (matches) {
Expand All @@ -146,7 +146,7 @@ function checkAnswer(answerline, givenAnswer, isFormattedAnswerline) {
return string;
}
}

const extractQuotes = (string) => {
let matches = string.match(/(?<=["])[^"]*(?=["])/g);
if (matches) {
Expand All @@ -155,7 +155,7 @@ function checkAnswer(answerline, givenAnswer, isFormattedAnswerline) {
return string;
}
}

answerline = removeParentheses(answerline);
let { mainAnswer, subAnswer } = splitMainAnswer(answerline);
const subPhrases = splitIntoPhrases(subAnswer);
Expand All @@ -169,7 +169,7 @@ function checkAnswer(answerline, givenAnswer, isFormattedAnswerline) {
subPhrases.forEach(phrase => {
if (phrase.length === 0) return;
let { directive, answers } = splitIntoAnswers(phrase);
answers.forEach(answer => {
answers.forEach(answer => {
if (directive === 'accept' || directive === 'prompt') {
answer = extractUnderlining(answer);
} else if (directive === 'reject') {
Expand All @@ -178,7 +178,7 @@ function checkAnswer(answerline, givenAnswer, isFormattedAnswerline) {
parsedAnswerline[directive].push(answer);
});
})

return parsedAnswerline;
}

Expand Down

0 comments on commit aba5893

Please sign in to comment.