fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 124: Binary search for a value in sorted array
Idiom # 124: Binary search for a value in sorted array
See
programming-idioms.org
:
Code
binary_search(arr container.sorted_array T, x T) i32 => match arr.find_key x nil => -1 i i32 => i
What are effects?
Running Example
ex124 is binary_search(arr container.sorted_array i32, x i32) i32 => match arr.find_key x nil => -1 i i32 => i unsorted := [0, 8, 15, 47, 11] a := unsorted.sort say (binary_search a 0) say (binary_search a 8) say (binary_search a 11) say (binary_search a 15) say (binary_search a 47) say (binary_search a 13)
What are effects?
last changed: 2024-07-01
next: Idiom # 125: Measure function call duration