Skip to content

Commit

Permalink
fix: remove codesandbox autogeneration because it breaks the build
Browse files Browse the repository at this point in the history
  • Loading branch information
panzerdp committed Sep 2, 2023
1 parent 0bf7155 commit 23ca627
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion posts/174-javascript-enums/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Let's consider the sizes of a T-shirt: `Small`, `Medium`, and `Large`.

A simple way (though not the most optimal, see the approaches below) to create an enum in JavaScript is to use a [plain JavaScript object](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Basics).

```javascript codesandbox=vanilla?previewwindow=console
```javascript
const Sizes = {
Small: 'small',
Medium: 'medium',
Expand Down
14 changes: 7 additions & 7 deletions posts/177-pure-function/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Let's see in more detail what are pure functions and why they are useful.

A function that returns the sum of 2 numbers is pure:

```javascript codesandbox=vanilla?previewwindow=console
```javascript
function sum(a, b) {
return a + b
}
Expand Down Expand Up @@ -83,7 +83,7 @@ A side effect is change to external state or environment outside of the [functio

If the `sum()` function logs to the console, then the function is not pure because it produces a side effect:

```javascript mark=3 codesandbox=vanilla?previewwindow=console
```javascript mark=3
function sumSideEffect(a, b) {
const s = a + b
console.log(s) // Side effect!
Expand Down Expand Up @@ -143,7 +143,7 @@ Pure functions are easy to *compose*. Simple pure functions can be composed to c

For example, you can use reuse the pure `sum()` function to calculate the sum of an array:

```js mark=6[23:25] codesandbox=vanilla?previewwindow=console
```js mark=6[23:25]
function sum(a, b) {
return a + b
}
Expand All @@ -165,7 +165,7 @@ In practice, a function becomes impure when it reads or modifies an external sta

A good example of an impure function is the built-in JavaScript random generator [Math.random()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random):

```javascript codesandbox=vanilla?previewwindow=console
```javascript
console.log(Math.random()) // logs 0.8891108266488603
console.log(Math.random()) // logs 0.9590062769956789
```
Expand All @@ -176,7 +176,7 @@ console.log(Math.random()) // logs 0.9590062769956789

Here's another example of an impure function:

```javascript codesandbox=vanilla?previewwindow=console
```javascript
let value = 0

function add(increase) {
Expand Down Expand Up @@ -232,7 +232,7 @@ If you are lucky, some impure functions can be transformed into pure by refactor

The following function adds default properties to an object. The function is impure because the parameter `original` is mutated:

```javascript codesandbox=vanilla?previewwindow=console
```javascript
function addDefaultsImpure(original, defaults) {
return Object.assign(original, defaults)
}
Expand All @@ -250,7 +250,7 @@ The problem with `addDefaultsImpure()` is the cognitive load: you have to *remem

Let's make the function pure by using an immutable merge operation:

```javascript codesandbox=vanilla?previewwindow=console
```javascript
function addDefaultsPure(original, defaults) {
return Object.assign({}, original, defaults)
}
Expand Down

0 comments on commit 23ca627

Please sign in to comment.