feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
This commit is contained in:
committed by
GitHub
parent
0095583028
commit
ee1e8abd87
@ -3,6 +3,7 @@ id: 59667989bf71cf555dd5d2ff
|
||||
title: S-表达式
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
dashedName: s-expressions
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -31,5 +32,43 @@ assert.deepEqual(parseSexpr(simpleSExpr), simpleSolution);
|
||||
assert.deepEqual(parseSexpr(basicSExpr), basicSolution);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
const simpleSExpr = '(data1 data2 data3)';
|
||||
const simpleSolution = ['data1', 'data2', 'data3'];
|
||||
|
||||
const basicSExpr = '((data "quoted data" 123 4.5) (data (!@# (4.5) "(more" "data)")))';
|
||||
const basicSolution = [["data","\"quoted data\"",123,4.5],["data",["!@#",[4.5],"\"(more\"","\"data)\""]]];
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function parseSexpr(str) {
|
||||
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function parseSexpr(str) {
|
||||
const t = str.match(/\s*("[^"]*"|\(|\)|"|[^\s()"]+)/g);
|
||||
for (var o, c = 0, i = t.length - 1; i >= 0; i--) {
|
||||
var n,
|
||||
ti = t[i].trim();
|
||||
if (ti == '"') return;
|
||||
else if (ti == '(') t[i] = '[', c += 1;
|
||||
else if (ti == ')') t[i] = ']', c -= 1;
|
||||
else if ((n = +ti) == ti) t[i] = n;
|
||||
else t[i] = `'${ti.replace('\'', '\\\'')}'`;
|
||||
if (i > 0 && ti != ']' && t[i - 1].trim() != '(') t.splice(i, 0, ',');
|
||||
if (!c) if (!o) o = true; else return;
|
||||
}
|
||||
return c ? undefined : eval(t.join(''));
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user