diff --git a/monoid-design.md b/monoid-design.md index ec414b14d3d9b4979f3cf7acdf142838f6928236..29f6705a4e8005b072b0d02aad0e67c1933bb384 100644 --- a/monoid-design.md +++ b/monoid-design.md @@ -57,7 +57,7 @@ ## Iterative Reducers -``` +```js function iterativeReduce(monoid, sequence) { let result = monoid.identity; for (const element of sequence) { @@ -71,7 +71,7 @@ function iterativeReduce(monoid, sequence) { ## Recursive Reducers -``` +```js function recursiveReduce(monoid, sequence) { if (sequence.length === 0) { return monoid.identity; @@ -122,7 +122,7 @@ function recursiveReduce(monoid, sequence) { * In Code: - ``` + ```js async function parallelReduce(monoid, sequence, threadCount) { const jobs = []; for (let threadIndex = 0; threadIndex < threadCount; ++threadIndex) { @@ -241,7 +241,7 @@ Problem: Given a string of parentheses, determine if the parentheses are balance ## Clues about the Monoid from an Iterative Design -``` +```js function isBalanced(parentheses) { let nesting = 0; for (const character of parentheses) { @@ -300,7 +300,7 @@ function isBalanced(parentheses) { ## New Iterative Solution -``` +```js function encode(character) { if (character === '(') { return […, …]; @@ -327,7 +327,7 @@ function iterativeReduce(parentheses) { ## Parallel Solution -``` +```js async function parallelReduce(parentheses, threadCount) { const jobs = []; for (let threadIndex = 0; threadIndex < threadCount; ++threadIndex) {