Date: 2016/08/11 18:22:04 UTC-07:00
Type: Denizen Script
DUL_find_best_match:
type: procedure
debug: false
DUL:
author:
- BlackCoyote
description:
- Returns the best search match out of a list.
usage:
- <proc[DUL_find_best_match].context[<list>|<value>]>
example:
- <proc[DUL_find_best_match].context[<server.flag[homes].as_list>|<context.args.get[1]>]>
script:
- define l '<queue.definitions.numerical>'
- define list 'li@'
- foreach '<def[l]>':
- define list '<def[list].include[<def[%loop_index%]>]>'
- define match '<def[list].last>'
- if <def[list].is_empty||true> {
- debug error "DUL - No valid list specified!"
- determine null
}
- if <def[match]||null> == null {
- debug error "DUL - No valid value specified!"
- determine null
}
- if <def[list].contains[<def[match]>]> {
- determine <def[match]>
} else if <def[list].filter[starts_with[<def[match]>]].size||0> > 0 {
- determine <def[list].filter[starts_with[<def[match]>]].sort_by_number[length].first||null>
} else if <def[list].filter[contains[<def[match]>]].size||0> > 0 {
- determine <def[list].filter[contains[<def[match]>]].sort_by_number[length].first||null>
} else {
- determine null
}