refactor: remove before after user code (#59204)

This commit is contained in:
Oliver Eyton-Williams
2025-09-30 18:41:16 +02:00
committed by GitHub
parent 8eab57a548
commit 58802c8112
7 changed files with 49 additions and 191 deletions
@@ -45,20 +45,6 @@ assert(typeof a === 'number' && a === 7);
# --seed--
## --before-user-code--
```js
if (typeof a != 'undefined') {
a = undefined;
}
```
## --after-user-code--
```js
(function(a){return "a = " + a;})(a);
```
## --seed-contents--
```js
@@ -24,6 +24,12 @@ Then we can call `testFun` like this: `testFun("Hello", "World");`. We have pass
<ol><li>Create a function called <code>functionWithArgs</code> that accepts two arguments and outputs their sum to the dev console.</li><li>Call the function with two numbers as arguments.</li></ol>
# --before-each--
```js
var logOutput;
```
# --hints--
`functionWithArgs` should be a function.
@@ -35,22 +41,20 @@ assert(typeof functionWithArgs === 'function');
`functionWithArgs(1,2)` should output `3`.
```js
if (typeof functionWithArgs === 'function') {
capture();
functionWithArgs(1, 2);
uncapture();
}
console.log = function (message) {
logOutput = message
};
functionWithArgs(1, 2);
assert(logOutput == 3);
```
`functionWithArgs(7,9)` should output `16`.
```js
if (typeof functionWithArgs === 'function') {
capture();
functionWithArgs(7, 9);
uncapture();
}
console.log = function (message) {
logOutput = message
};
functionWithArgs(7, 9);
assert(logOutput == 16);
```
@@ -66,43 +70,6 @@ assert(
# --seed--
## --before-user-code--
```js
var logOutput = "";
var originalConsole = console
function capture() {
var nativeLog = console.log;
console.log = function (message) {
if(message) logOutput = JSON.stringify(message).trim();
if(nativeLog.apply) {
nativeLog.apply(originalConsole, arguments);
} else {
var nativeMsg = Array.prototype.slice.apply(arguments).join(' ');
nativeLog(nativeMsg);
}
};
}
function uncapture() {
console.log = originalConsole.log;
}
capture();
```
## --after-user-code--
```js
uncapture();
if (typeof functionWithArgs !== "function") {
(function() { return "functionWithArgs is not defined"; })();
} else {
(function() { return logOutput || "console.log never called"; })();
}
```
## --seed-contents--
```js
@@ -44,48 +44,8 @@ assert(nextInLine([2], 1) === 2);
assert(nextInLine([5, 6, 7, 8, 9], 1) === 5);
```
After `nextInLine(testArr, 10)`, `testArr[4]` should be `10`
```js
nextInLine(testArr, 10);
assert(testArr[4] === 10);
```
# --seed--
## --before-user-code--
```js
var logOutput = [];
var originalConsole = console
function capture() {
var nativeLog = console.log;
console.log = function (message) {
logOutput.push(message);
if(nativeLog.apply) {
nativeLog.apply(originalConsole, arguments);
} else {
var nativeMsg = Array.prototype.slice.apply(arguments).join(' ');
nativeLog(nativeMsg);
}
};
}
function uncapture() {
console.log = originalConsole.log;
}
capture();
```
## --after-user-code--
```js
uncapture();
testArr = [1,2,3,4,5];
(function() { return logOutput.join("\n");})();
```
## --seed-contents--
```js
@@ -27,6 +27,30 @@ Complete the function using the rules below to modify the object passed to the f
**Note:** A copy of the `recordCollection` object is used for the tests. You should not directly modify the `recordCollection` object.
# --before-each--
```js
const _recordCollection = {
2548: {
albumTitle: 'Slippery When Wet',
artist: 'Bon Jovi',
tracks: ['Let It Rock', 'You Give Love a Bad Name']
},
2468: {
albumTitle: '1999',
artist: 'Prince',
tracks: ['1999', 'Little Red Corvette']
},
1245: {
artist: 'Robert Palmer',
tracks: []
},
5439: {
albumTitle: 'ABBA Gold'
}
};
```
# --hints--
After `updateRecords(recordCollection, 5439, "artist", "ABBA")`, `artist` should be the string `ABBA`
@@ -94,30 +118,6 @@ assert(
# --seed--
## --before-user-code--
```js
const _recordCollection = {
2548: {
albumTitle: 'Slippery When Wet',
artist: 'Bon Jovi',
tracks: ['Let It Rock', 'You Give Love a Bad Name']
},
2468: {
albumTitle: '1999',
artist: 'Prince',
tracks: ['1999', 'Little Red Corvette']
},
1245: {
artist: 'Robert Palmer',
tracks: []
},
5439: {
albumTitle: 'ABBA Gold'
}
};
```
## --seed-contents--
```js
@@ -45,25 +45,6 @@ assert(/b\s*=\s*a\s*/g.test(__helpers.removeJSComments(code)));
# --seed--
## --before-user-code--
```js
if (typeof a != 'undefined') {
a = undefined;
}
if (typeof b != 'undefined') {
b = undefined;
}
```
## --after-user-code--
```js
(function(a, b) {
return 'a = ' + a + ', b = ' + b;
})(a, b);
```
## --seed-contents--
```js
@@ -79,55 +79,23 @@ assert(beagle.constructor === Dog);
`beagle.eat()` should log the string `nom nom nom`
```js
capture();
const spy = __helpers.spyOn(console, 'log');
beagle.eat();
uncapture();
assert(logOutput == 'nom nom nom');
assert.lengthOf(spy.calls,1);
assert(spy.calls[0][0] == 'nom nom nom');
```
`beagle.bark()` should log the string `Woof!`
```js
capture();
const spy = __helpers.spyOn(console, 'log');
beagle.bark();
uncapture();
assert(logOutput == 'Woof!');
assert.lengthOf(spy.calls,1);
assert(spy.calls[0][0] == 'Woof!');
```
# --seed--
## --before-user-code--
```js
var logOutput = "";
var originalConsole = console
function capture() {
var nativeLog = console.log;
console.log = function (message) {
logOutput = message;
if(nativeLog.apply) {
nativeLog.apply(originalConsole, arguments);
} else {
var nativeMsg = Array.prototype.slice.apply(arguments).join(' ');
nativeLog(nativeMsg);
}
};
}
function uncapture() {
console.log = originalConsole.log;
}
capture();
```
## --after-user-code--
```js
uncapture();
(function() { return logOutput || "console.log never called"; })();
```
## --seed-contents--
```js
@@ -26,7 +26,7 @@ In order, the three `match` calls would return the values `["goooooooo"]`, `["g"
# --instructions--
For this challenge, `chewieQuote` has been initialized as the string `Aaaaaaaaaaaaaaaarrrgh!` behind the scenes. Create a regex `chewieRegex` that uses the `*` character to match an uppercase `A` character immediately followed by zero or more lowercase `a` characters in `chewieQuote`. Your regex does not need flags or character classes, and it should not match any of the other quotes.
Create a regex `chewieRegex` that uses the `*` character to match an uppercase `A` character immediately followed by zero or more lowercase `a` characters in `chewieQuote`. Your regex does not need flags or character classes, and it should not match any of the other quotes.
# --hints--
@@ -72,15 +72,10 @@ assert(
# --seed--
## --before-user-code--
```js
const chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!";
```
## --seed-contents--
```js
const chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!";
// Only change code below this line
let chewieRegex = /change/; // Change this line
// Only change code above this line
@@ -91,6 +86,7 @@ let result = chewieQuote.match(chewieRegex);
# --solutions--
```js
let chewieRegex = /Aa*/;
let result = chewieQuote.match(chewieRegex);
const chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!";
let chewieRegex = /Aa*/;
let result = chewieQuote.match(chewieRegex);
```