@@ -134,20 +134,19 @@ import {
134
134
} from ' lfi'
135
135
136
136
// The file has one sloth name per line
137
- const filename = ` every-sloth-name.txt`
137
+ const FILENAME = ` every-sloth-name.txt`
138
+ const API_URL = ` https://random-word-form.herokuapp.com/random/adjective`
138
139
139
140
const slothSquadStatementsPromise = pipe (
140
141
// Create an async iterable over the file lines, in this case sloth names
141
- (await fetch (new URL (` https://lfi.dev/${ filename } ` ))).body ,
142
+ (await fetch (new URL (` https://lfi.dev/${ FILENAME } ` ))).body ,
142
143
flatMapAsync (chunk => new TextDecoder ().decode (chunk).split (` \n ` )),
143
144
// Chunk the sloth names into array groups of 4, also known as a sloth squad
144
145
chunkAsync (4 ),
145
146
// Transform each sloth squad into a statement by asynchronously querying an
146
147
// API for an adjective to describe the squad
147
148
mapAsync (async slothSquad => {
148
- const [adjective ] = await (
149
- await fetch (` https://random-word-form.herokuapp.com/random/adjective` )
150
- ).json ()
149
+ const [adjective ] = await (await fetch (API_URL )).json ()
151
150
const leadingSloths = slothSquad .slice (0 , 3 )
152
151
const trailingSloth = slothSquad .at (- 1 )
153
152
return ` ${ leadingSloths .join (` , ` )} , and ${ trailingSloth} are ${ adjective} !`
@@ -195,11 +194,12 @@ import {
195
194
} from ' lfi'
196
195
197
196
// The file has one sloth name per line
198
- const filename = ` every-sloth-name.txt`
197
+ const FILENAME = ` every-sloth-name.txt`
198
+ const API_URL = ` https://random-word-form.herokuapp.com/random/adjective`
199
199
200
200
const slothSquadStatementsPromise = pipe (
201
201
// Create an async iterable over the file lines, in this case sloth names
202
- (await fetch (new URL (` https://lfi.dev/${ filename } ` ))).body ,
202
+ (await fetch (new URL (` https://lfi.dev/${ FILENAME } ` ))).body ,
203
203
flatMapAsync (chunk => new TextDecoder ().decode (chunk).split (` \n ` )),
204
204
// Chunk the sloth names into array groups of 4, also known as a sloth squad
205
205
chunkAsync (4 ),
@@ -211,9 +211,7 @@ const slothSquadStatementsPromise = pipe(
211
211
// API for an adjective to describe the squad, all concurrently with other
212
212
// squads
213
213
mapConcur (async slothSquad => {
214
- const [adjective ] = await (
215
- await fetch (` https://random-word-form.herokuapp.com/random/adjective` )
216
- ).json ()
214
+ const [adjective ] = await (await fetch (API_URL )).json ()
217
215
const leadingSloths = slothSquad .slice (0 , 3 )
218
216
const trailingSloth = slothSquad .at (- 1 )
219
217
return ` ${ leadingSloths .join (` , ` )} , and ${ trailingSloth} are ${ adjective} `
@@ -225,6 +223,7 @@ const slothSquadStatementsPromise = pipe(
225
223
)
226
224
227
225
console .log (await slothSquadStatementsPromise)
226
+ // NOTE: This order may change between runs
228
227
// => [
229
228
// => 'strawberry, max, bitsy, and tommy jolly!',
230
229
// => 'ava, brooke, lottie, and jeremiah are beloved!',
0 commit comments