for (let i = 0; i < count; i++) {
random_move(board);
}
Is probably the clearest way to write it. While for loops aren't very aesthetic, they are simple and very clear, and easily recognizable to JavaScript programmers.
If you really wanted to get rid of it, you could use something like
for (let i of _.range(count)) {
but since this isn't an established idiom, it takes more mental effort to read even if it is prettier.
I notice that random_move is actually doing too much. It shouldn't choose a move and execute it; it should just choose a move. The shuffle function body is the place where you should call process_move.
I think
Is probably the clearest way to write it. While
for
loops aren't very aesthetic, they are simple and very clear, and easily recognizable to JavaScript programmers.If you really wanted to get rid of it, you could use something like
but since this isn't an established idiom, it takes more mental effort to read even if it is prettier.
I notice that
random_move
is actually doing too much. It shouldn't choose a move and execute it; it should just choose a move. Theshuffle
function body is the place where you should callprocess_move
.:)
Oh yes. Thank you!