Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

euphoria
functions
sequence
communitycreator

What is the ends() function 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

The data type sequence has a lot of operations that can be carried out on them. We can insert, match, delete, and even compare its members. These operations are fulfilled using different functions that are inbuilt in Euphoria. In this shot, a function that checks if we can find a sequence at the end of another will be discussed.

The ends() function

This function is part of the method from the search.e package of the standard library in Euphoria. The ends() function checks if a sequence ends another sequence or not. If the said sequence can be found at the end of the other, the function returns 1. If not, it returns 0.

Syntax

ends(sub_string, full_string)

Parameters

  • sub_string: This is a set of characters or a text that is being checked to see if it ends another larger set of characters/text.
  • full_string: The end of this sequence value will be checked to see if it contains another sequence, the sub_string parameter.

Return value

  • This function returns an integer 1 if sub_string is found at the end of full_string. Otherwise, it returns 0.

To use this function, we have to add include std/search.e at the top of our program code.

Code

In the code snippet below, we’ll check for the availability of some sequence at the end of a few strings.

include std/search.e

atom out1, out2, out3
sequence mainSeq, subSeq1,subSeq2,subSeq3
mainSeq = "The sky looks very calm today"
subSeq1 = "today"
subSeq2 = "calm"
subSeq3 = "ay"

out1 = ends(subSeq1,mainSeq)
out2 = ends(subSeq2,mainSeq)
out3 = ends(subSeq3,mainSeq)
printf(1,"\nThe output is 1, because \"today\" ends variable \"mainSeq\" : %d",out1)
printf(1,"\nThe output is 0, because \"calm\" didn\'t ends variable \"mainSeq\" : %d",out2)
printf(1,"\nThe output is 1, because \"ay\" ends variable \"mainSeq\" : %d",out3)

Explanation

  • Line 1: We add the search.e file to the program to access its methods.
  • Line 3: We declare atom variables that will hold the outcome of the ends() method operation.
  • Line 4: We declare the sequence variables.
  • Lines 5–8: We assign values to already declared variables.
  • Lines 10–12: We use the ends() method to query a string for another and save the return value to out1, out2, and out3 atom variables that have been declared earlier on.
  • Lines 13–15: We print the output of the ends() method operation.

RELATED TAGS

euphoria
functions
sequence
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