Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

euphoria
communitycreator

What is the find() method in Euphoria?

NDUKWE CHIDERA K.

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

There are a good number of methods for basic search operations in Euphoria. Such operations include getting a match or finding a particular element from a sequence.

In this shot, we look at one of these methods: find().

The find() method

The find() method conducts a search operation. This method locates an atom or a sub-sequence by searching a sequence from a specified position.

To search for an atom or subsequence in a sequence, we have to provide what we are searching for, where it can be found, and where we want the search to start.

Syntax

find(to_be_found,find_in,startpoint)

Parameters

  • to_be_found: This is the value of the object data type whose presence we are querying for.

  • find_in: This is the sequence we are querying in to find a specified set of characters.

  • startpoint: This is an integer value that indicates the index position to start the query/search.

Return value

  • This method returns the value 0 if the value being queried for is not found.
  • This method returns the index position of the value in the sequence, if found. This is usually the index value of the first element when a sequence is being queried for.

Code

Here is a simple code demonstration to illustrate the find() method.

--declare variables
sequence ages, name, snacks

--assign values
snacks = {"burger","cookies","burger","pizza"}
name =  {"Magdalineali", "jamie", "kent","magda"}
ages = {12,13,14,15,16,17,12}

printf(1,"Can find burger: %d",find("burger",snacks))
printf(1,"\nfind magda: %d",find("magda",name))
printf(1,"\nfind 12 start from index 1: %d",find(12,ages,3))

Explanation

  • Line 2: We declare the variables name, ages, and snacks as types of sequence.
  • Lines 5 to 7: We assign variables to snacks,ages, and name respectively.
  • Lines 9 to 11: We use the find() method to query the earlier defined sequence for the indicated string. Then, we print the output to the screen.

Note: The function ends the query immediately if it finds any occurrence of the value being searched for, and returns its index value.

RELATED TAGS

euphoria
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring