freeCodeCamp/curriculum/challenges/italian/15-javascript-algorithms-an.../learn-functional-programmin.../step-017.md

101 lines
1.8 KiB
Markdown
Raw Normal View History

---
id: 5d79253386060ed9eb04a070
title: Step 17
challengeType: 0
dashedName: step-17
---
# --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).
# --hints--
See description above for instructions.
```js
assert(code.replace(/\s/g, '').includes('str.replace(regex,(_'));
```
# --seed--
## --before-user-code--
```html
<!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-user-code--
```html
</body>
</html>
```
## --seed-contents--
```html
<script>
const infixToFunction = {
"+": (x, y) => x + y,
"-": (x, y) => x - y,
"*": (x, y) => x * y,
"/": (x, y) => x / y
};
--fcc-editable-region--
const infixEval = (str, regex) =>
str.replace(regex, (match, arg1, fn, arg2) =>
infixToFunction[fn](parseFloat(arg1), parseFloat(arg2))
);
--fcc-editable-region--
</script>
```
# --solutions--
```html
<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>
```