Ruby | Array bsearch_index() operation Last Updated : 08 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Array#bsearch_index() : bsearch_index() is an Array class method which finds the index of the array value that meets with the given condition. Its complexity is O(log n) where n is the array size. This method can work in both the modes - find-minimum and find-any mode. Syntax: Array.bsearch_index() Parameter: - Arrays to search elements. - condition block Return: Index value of the array element that satisfy the given condition Code #1 : Example for bsearch_index() method Ruby # Ruby code for bsearch_index() method # declaring array a = [1, 2, 3, 4] # declaring array b = [111.11, 2.5, 4.3, 2.224] # array that meets the condition puts "search : #{a.bsearch_index {|x| x >=4 }}\n\n" puts "search : #{b.bsearch_index {|x| x >=3 }}\n\n" puts "search : #{a.bsearch_index {|x| x >=2 }}\n\n" puts "search : #{b.bsearch_index {|x| x >=2 }}\n\n" Output : search : 3 search : 2 search : 1 search : 0 Code #2 : Example for bsearch_index() method Ruby # Ruby code for bsearch_index() method # declaring array a = [1, 2, 3, 4] # declaring array b = [111.11, 2.5, 4.3, 2.224] # array that meets the condition puts "search : #{a.bsearch_index {|x| 1 - x / 4 }}\n\n" puts "search : #{b.bsearch_index {|x| 2*x > 1 }}\n\n" Output : search : 3 search : 0 Comment More infoAdvertise with us Next Article Ruby | Array bsearch_index() operation M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby Array-class Similar Reads Ruby | Array bsearch() operation Array#bsearch() : bsearch() is an Array class method which finds a value from the array that meets with the given condition. It's complexity is O(log n) where n is the array size. This method can work in both the modes - find-minimum and find-any mode. Syntax: Array.bsearch() Parameter: - Arrays to 2 min read Ruby | Array class each_index() operation Array#each_index() : each_index() is a Array class method which returns the index of the array element by following the condition in the given block once for each_index element in self. Syntax: Array.each_index() Parameter: block - condition to follow Return: index of the array element following the 1 min read Ruby | Array class each() operation Array#each() : each() is a Array class method which returns the array by following the condition in the given block once for each element in self. Syntax: Array.each() Parameter: block - condition to follow Return: Each array element following the condition Code #1 : Example for each() method Ruby # 1 min read Ruby | Array class find_index() operation Array#find_index() : find_index() is a Array class method which returns the index of the first array. If a block is given instead of an argument, returns the index of the first object for which the block returns true. Syntax: Array.find_index() Parameter: block - condition to follow Return: index va 1 min read Ruby | Array class include?() operation Array#include?() : include?() is a Array class method checks if the argumented object is present in the array or not. Syntax: Array.include?() Parameter: obj - element to find Return: true - if the element is present; otherwise false Code #1 : Example for include?() method Ruby # Ruby code for inclu 1 min read Like