Skip to content

Commit a2d8930

Browse files
committed
format output
1 parent b1f0bae commit a2d8930

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

_posts/2015-02-21-interviewing-for-a-front-end-job.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ const takeIterable = (numberToTake, iterable) =>
134134
});
135135

136136
Array.from(takeIterable(10, Game()))
137-
//=> ["↑","←","→","←","→","←","→","←","→","←"]
137+
//=>
138+
["↑","←","→","←","→","←","→","←","→","←"]
138139
{% endhighlight %}
139140

140141
But now to the business. We want to take the arrows and convert them to positions. For that, we'll map the Game iterable to positions. A `statefulMap` is a lazy map that preserves state from iteration to iteration. That's what we need, because we need to know the current position to map each move to the next position:
@@ -161,7 +162,8 @@ const indexed = statefulMapIterableWith(
161162
["prince", "of", "darkness"])
162163

163164
Array.from(indexed)
164-
//=> [[0,"prince"],[1,"of"],[2,"darkness"]]
165+
//=>
166+
[[0,"prince"],[1,"of"],[2,"darkness"]]
165167
{% endhighlight %}
166168

167169
Armed with this, it's straightforward to map an iterable of directions to an iterable of strings representing positions:
@@ -184,10 +186,11 @@ const positionsOf = (game) =>
184186
game);
185187

186188
Array.from(takeIterable(10, positionsOf(Game())))
187-
//=> ["x: -1, y: 0","x: 0, y: 1","x: -1, y: 0",
188-
"x: 0, y: -1","x: 0, y: 1","x: 0, y: -1",
189-
"x: 0, y: 1","x: 0, y: -1","x: 0, y: 1",
190-
"x: 0, y: -1"]
189+
//=>
190+
["x: -1, y: 0","x: 0, y: 1","x: -1, y: 0",
191+
"x: 0, y: -1","x: 0, y: 1","x: 0, y: -1",
192+
"x: 0, y: 1","x: 0, y: -1","x: 0, y: 1",
193+
"x: 0, y: -1"]
191194
{% endhighlight %}
192195

193196
The Carpenter reflected. "Having turned our game loop into an iterable, we can now see that our problem of whether the game terminates is isomorphic to the problem of detecting whether the positions given ever repeat themselves: If the chequer ever returns to a position it has previously visited, it will cycle endlessly."

0 commit comments

Comments
 (0)