Here is my attempt at a function that checks if a value is being repeated {x} times consecutively.
Code: Select all
fn_checkConsecutiveValues(param_arr, param_maxInARow:=1) {
consecutiveCounter := 0
for key, value in param_arr {
; skip on first element
if (A_Index == 1) {
continue
}
; perform main idea
if (param_arr[A_Index - 1] = value) {
consecutiveCounter++
} else {
consecutiveCounter := 0
}
; check if too many consecutives
if (consecutiveCounter >= param_maxInARow) {
return false
}
}
; param_maxInARow was never exceeded
return true
}
For flexibility,
param_maxInARow can be set to 1 (No consecutive uses); or a different amount as desired.
It returns
true when the input array was not too consecutive, else
false
For example
["ja", "ja", "ja"] will return
false with a "param_maxInARow" setting of two or lower; while
["ja", "ning", "ja", "ning", "ja"] will always return
true because no values repeat in a row.
All that's left is to filter all other words.
Code: Select all
A := new biga() ; requires https://github.com/biga-ahk/biga.ahk
userInput := "Ma armastan kooke ja kooke ja kõige rohkem magustoite; Ja ärge unustage pudingut."
filterWordsArr := A.filter(A.words(userInput), func("fn_filterJaNing"))
; => ["ja", "ja", "Ja"]
msgbox, % fn_checkConsecutiveValues(filterWordsArr, 1)
; => false
userInput := "Ma armastan kooke ja kooke ning kõige rohkem magustoite; Ja ärge unustage pudingut."
filterWordsArr := A.filter(A.words(userInput), func("fn_filterJaNing"))
; => ["ja", "ning", "Ja"]
msgbox, % fn_checkConsecutiveValues(filterWordsArr, 1)
; => true
; functions
fn_filterJaNing(param_input) {
if (param_input = "ja" || param_input = "ning") {
return true
}
}
This does not solve any 'while typing' or 'for each sentence' challenge. But I hope it helps