diff --git a/VocabularyTrainer/Trainer.cs b/VocabularyTrainer/Trainer.cs
index 890c42d..1e65c67 100644
--- a/VocabularyTrainer/Trainer.cs
+++ b/VocabularyTrainer/Trainer.cs
@@ -88,7 +88,30 @@ public sealed class Trainer
/// A for each (valid) word
private static VocabularyItem[] CreateVocabularyItems(string[][] wordsAndTranslations)
{
- // TODO
- return [];
+ VocabularyItem[] vocabularyItemsTemp = new VocabularyItem[wordsAndTranslations.Length];
+ bool[] definedItems = new bool[wordsAndTranslations.Length];
+ int usedItems = 0;
+ for (var i = 0; i < wordsAndTranslations.Length; i++)
+ {
+ if (wordsAndTranslations[i].Length == 2)
+ {
+ usedItems++;
+ definedItems[i] = true;
+ vocabularyItemsTemp[i] = new VocabularyItem(wordsAndTranslations[i][WordIdx], wordsAndTranslations[i][TranslationIdx]);
+ }
+ }
+
+ VocabularyItem[] vocabularyItems = new VocabularyItem[usedItems];
+ int j = 0;
+ for (int i = 0; i < wordsAndTranslations.Length; i++)
+ {
+ if (definedItems[i])
+ {
+ vocabularyItems[j] = vocabularyItemsTemp[i];
+ j++;
+ }
+ }
+
+ return vocabularyItems;
}
}
\ No newline at end of file
diff --git a/VocabularyTrainer/VocabularyItem.cs b/VocabularyTrainer/VocabularyItem.cs
index adb8828..c1fd457 100644
--- a/VocabularyTrainer/VocabularyItem.cs
+++ b/VocabularyTrainer/VocabularyItem.cs
@@ -10,7 +10,7 @@ public sealed class VocabularyItem
public readonly string NativeWord;
public readonly string Translation;
- VocabularyItem(string nativeWord, string translation)
+ public VocabularyItem(string nativeWord, string translation)
{
NativeWord = nativeWord;
Translation = translation;
@@ -41,7 +41,18 @@ public sealed class VocabularyItem
/// 0 if equal; less than 0 if this item is smaller; greater than 0 otherwise
public int CompareTo(VocabularyItem other)
{
- return -1;
+ if (_countCorrect == other._countCorrect)
+ {
+ return CompareStrings(NativeWord, other.NativeWord);
+ }
+ else if (_countCorrect < other._countCorrect)
+ {
+ return 1;
+ }
+ else
+ {
+ return -1;
+ }
}
///
@@ -50,7 +61,7 @@ public sealed class VocabularyItem
/// A string containing the word, its translation and the training statistics
public override string ToString()
{
- return string.Empty;
+ return $"{NativeWord,-10} {Translation,-10} {_countAsked,-5} {_countCorrect,-7}";;
}
///
@@ -60,8 +71,6 @@ public sealed class VocabularyItem
/// Second string
/// Less than 0 if a precedes b in the sorting order; greater than 0 if b precedes a; 0 otherwise
- private static int CompareStrings(string a, string b)
- {
- return -1;
- }
+ private static int CompareStrings(string a, string b) => string.Compare(a, b, StringComparison.OrdinalIgnoreCase);
+
}
\ No newline at end of file