* fix: renamed basic html cat photo app steps * fix: renamed css-variables project steps * fix: renamed d3-dashboard filenames * fix: renamed rpg-game filenames * fix: renamed functional-progamming-spreadsheet filenames * fix: renamed calorie-counter project filenames
2.1 KiB
2.1 KiB
id, title, challengeType, isHidden
id | title | challengeType | isHidden |
---|---|---|---|
5d79253386060ed9eb04a070 | Part 17 | 0 | true |
Description
The match
parameter is currently unused, which can lead to unused variable warnings in some linters.
To fix this, prefix or replace it with an underscore (_
) - both ways signal to the reader and linter that you're aware you don't need this.
Note that a single underscore can only be used once in a function and may conflict with some libraries (Lodash, Underscore.js).
Instructions
Tests
tests:
- text: See description above for instructions.
testString: assert(code.replace(/\s/g, "").includes("str.replace(regex,(_"));
Challenge Seed
<script>
const infixToFunction = {
"+": (x, y) => x + y,
"-": (x, y) => x - y,
"*": (x, y) => x * y,
"/": (x, y) => x / y
};
const infixEval = (str, regex) =>
str.replace(regex, (match, arg1, fn, arg2) =>
infixToFunction[fn](parseFloat(arg1), parseFloat(arg2))
);
</script>
Before Test
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Spreadsheet</title>
<style>
#container {
display: grid;
grid-template-columns: 50px repeat(10, 200px);
grid-template-rows: repeat(11, 30px);
}
.label {
background-color: lightgray;
text-align: center;
vertical-align: middle;
line-height: 30px;
}
</style>
</head>
<body>
<div id="container">
<div></div>
</div>
After Test
</body>
</html>
Solution
<script>
const infixToFunction = {
"+": (x, y) => x + y,
"-": (x, y) => x - y,
"*": (x, y) => x * y,
"/": (x, y) => x / y
};
const infixEval = (str, regex) =>
str.replace(regex, (_, arg1, fn, arg2) =>
infixToFunction[fn](parseFloat(arg1), parseFloat(arg2))
);
</script>