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: a3f503de51cfab748ff001aa
|
||||
title: 成对
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
dashedName: pairwise
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -49,5 +50,37 @@ assert.deepEqual(pairwise([0, 0, 0, 0, 1, 1], 1), 10);
|
||||
assert.deepEqual(pairwise([], 100), 0);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function pairwise(arr, arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
pairwise([1,4,2,3,0,5], 7);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function pairwise(arr, arg) {
|
||||
var sum = 0;
|
||||
arr.forEach(function(e, i, a) {
|
||||
if (e != null) {
|
||||
var diff = arg-e;
|
||||
a[i] = null;
|
||||
var dix = a.indexOf(diff);
|
||||
if (dix !== -1) {
|
||||
sum += dix;
|
||||
sum += i;
|
||||
a[dix] = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
return sum;
|
||||
}
|
||||
|
||||
pairwise([1,4,2,3,0,5], 7);
|
||||
```
|
||||
|
Reference in New Issue
Block a user