Skip to content

Commit 956b2bc

Browse files
committed
fixes #5 by making the cards displayed more standard
1 parent c9a18ed commit 956b2bc

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.teamtreehouse.flashy.services;
22

3+
import static java.util.stream.Collectors.toList;
4+
35
import com.teamtreehouse.flashy.domain.FlashCard;
46
import com.teamtreehouse.flashy.repositories.FlashCardRepository;
5-
67
import org.springframework.beans.factory.annotation.Autowired;
78
import org.springframework.stereotype.Service;
89

@@ -12,8 +13,6 @@
1213
import java.util.Map;
1314
import java.util.Random;
1415

15-
import static java.util.stream.Collectors.toList;
16-
1716
@Service
1817
public class FlashCardServiceImpl implements FlashCardService {
1918
private FlashCardRepository flashCardRepository;
@@ -62,10 +61,9 @@ public FlashCard getNextFlashCardBasedOnViews(Map<Long, Long> idToViewCounts) {
6261
continue;
6362
}
6463
Long lowestScore = idToViewCounts.get(leastViewedId);
65-
if (entry.getValue() >= lowestScore) {
66-
break;
64+
if (entry.getValue() < lowestScore) {
65+
leastViewedId = entry.getKey();
6766
}
68-
leastViewedId = entry.getKey();
6967
}
7068
return flashCardRepository.findOne(leastViewedId);
7169
}
@@ -75,7 +73,7 @@ public List<FlashCard> getRandomFlashCards(int amount) {
7573
List<FlashCard> cards = flashCardRepository.findAll();
7674
Collections.shuffle(cards);
7775
return cards.stream()
78-
.limit(amount)
79-
.collect(toList());
76+
.limit(amount)
77+
.collect(toList());
8078
}
8179
}

0 commit comments

Comments
 (0)