Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

euphoria
url
communitycreator
compare

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

The compare() method compares two items and returns values indicating less than, equal to, or greater than as a result of the comparison.

Syntax

compare(value_to_compare, reference_value)

Parameter

  • value_to_compare: This is a value of an object data type that we want to compare to another value.
  • reference_value: This is the value of an object data type that serves as a reference point for the comparison.

Return value

This method returns an atom, which can be -1, 1 or 0.

  • 0 : If compared objects are identical.
  • -1 :If value_to_compare is less than reference_value.
  • 1: If value_to_compare is greater than reference_value.

Example

print(1,compare("group","group"))
puts(1,'\n')
print(1,compare("GrouP","group"))
puts(1,'\n')
print(1,compare("groups","group"))
puts(1,'\n')
print(1,compare("group","grouping"))
Comparison operations using compare()

Explanation

The puts() method in the code snippet is used to print a new line so that each code will execute on a line new. For each of the comparisons, the first parameter of the compare function is the value that will be compared with the second value which serves as the reference value.

  • Line 2: The output of the comparison here will be 0 because the compared values are identical.
  • Line 6: Two words that are the same in spelling but different in terms of the different letter case when compare still returns as -1, which indicates that the compared value is less than the reference value. The same is the case of code in line 12.
  • Line 10: We compare two values on this line where the compared value is greater than the referenced value, leaving the function to return 1.

RELATED TAGS

euphoria
url
communitycreator
compare

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