@@ -313,25 +313,22 @@ impl AppState {
313313
314314 // Return the index of the next pending exercise or `None` if all exercises are done.
315315 fn next_pending_exercise_ind ( & self ) -> Option < usize > {
316- if self . current_exercise_ind + 1 == self . exercises . len ( ) {
317- // The last exercise is done.
318- // Search for exercises not done from the start.
319- return self . exercises [ ..self . current_exercise_ind ]
320- . iter ( )
321- . position ( |exercise| !exercise. done ) ;
322- }
323-
324- // The done exercise isn't the last one.
325- // Search for a pending exercise after the current one and then from the start.
326- match self . exercises [ self . current_exercise_ind + 1 ..]
327- . iter ( )
328- . position ( |exercise| !exercise. done )
329- {
330- Some ( ind) => Some ( self . current_exercise_ind + 1 + ind) ,
331- None => self . exercises [ ..self . current_exercise_ind ]
332- . iter ( )
333- . position ( |exercise| !exercise. done ) ,
334- }
316+ let next_ind = self . current_exercise_ind + 1 ;
317+ self . exercises
318+ // If the exercise done isn't the last, search for pending exercises after it.
319+ . get ( next_ind..)
320+ . and_then ( |later_exercises| {
321+ later_exercises
322+ . iter ( )
323+ . position ( |exercise| !exercise. done )
324+ . map ( |ind| next_ind + ind)
325+ } )
326+ // Search from the start.
327+ . or_else ( || {
328+ self . exercises [ ..self . current_exercise_ind ]
329+ . iter ( )
330+ . position ( |exercise| !exercise. done )
331+ } )
335332 }
336333
337334 /// Official exercises: Dump the solution file form the binary and return its path.
0 commit comments