Skip to content

Commit

Permalink
impr: add backtick in javascript language when punctuation is enabled…
Browse files Browse the repository at this point in the history
… (ascodeasice) (#4801)

* refactor: logic for adding bracket in code language

* feat: add tick-wrapped words in javascript

* feat: add tick to javascript with punc
  • Loading branch information
ascodeasice committed Nov 20, 2023
1 parent 4b3059b commit 2f4eb10
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions frontend/src/ts/test/words-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ export async function punctuateWord(
} else if (Math.random() < 0.012 && lastChar !== "," && lastChar !== ".") {
if (currentLanguage === "code") {
const r = Math.random();
if (r < 0.25) {
word = `(${word})`;
} else if (r < 0.5) {
word = `{${word}}`;
} else if (r < 0.75) {
word = `[${word}]`;
} else {
word = `<${word}>`;
const brackets = ["()", "{}", "[]", "<>"];

// add `word` in javascript
if (Config.language.startsWith("code_javascript")) {
brackets.push("``");
}

const index = Math.floor(r * brackets.length);
const bracket = brackets[index];

word = `${bracket[0]}${word}${bracket[1]}`;
} else {
word = `(${word})`;
}
Expand Down Expand Up @@ -227,7 +229,11 @@ export async function punctuateWord(
) {
word = Misc.randomElementFromArray(specialsC);
} else {
word = Misc.randomElementFromArray(specials);
if (Config.language.startsWith("code_javascript")) {
word = Misc.randomElementFromArray([...specials, "`"]);
} else {
word = Misc.randomElementFromArray(specials);
}
}
} else if (
Math.random() < 0.5 &&
Expand Down

0 comments on commit 2f4eb10

Please sign in to comment.