Verified Commit ed640195 authored by ynerant's avatar ynerant
Browse files

Order output

parent b3768042
......@@ -166,6 +166,17 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Batch(cmds...)
}
func InsertWord(arr []word, w word) []word {
if len(arr) == 0 {
return append(arr, w)
}
w2 := arr[len(arr)-1]
if w.distance < w2.distance {
return append(arr, w)
}
return append(InsertWord(arr[:len(arr)-1], w), w2)
}
func (m model) InputWord() (model, tea.Cmd) {
input := m.textInput.Value()
......@@ -174,9 +185,8 @@ func (m model) InputWord() (model, tea.Cmd) {
m.maxLength = len(input)
}
// TODO: Get distance and ranking from a file
// TODO: Reorder the array
w := word{input, 200*rand.Float64() - 100, rand.Intn(1000)}
m.words = append(m.words, w)
m.words = InsertWord(m.words, w)
lineWidth := lipgloss.Width(fmt.Sprintf(
"* %s %s %s %4d ",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment