Order output
This commit is contained in:
parent
b3768042e4
commit
ed64019555
14
main.go
14
main.go
@ -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 ",
|
||||
|
Loading…
Reference in New Issue
Block a user