Questions tagged [compare]

The analysis required to assess the differences and similarities between two or more entities.

This tag is used to classify a question as one dealing with the comparison of at least two entities. The essence of questions that are tagged should boil down to one of the following questions:

  1. How do I control when the compiler/interpreter thinks that two entities are equal? How do I control when the compiler/interpreter thinks that two entities are unequal?
  2. How do I control when the compiler/interpreter thinks that one entity is bigger than the other?
  3. How do I control when the compiler/interpreter thinks that one entity is smaller than the other?

Note that in some languages, it is possible to define asymmetric inequalities. That is, cases in which a<b does not mean that b<a. This is why in python, there exist separate functions for __gt__ (greater than) and __lt__ (less than), etc

10212 questions
109
votes
5 answers

How can I compare a string to multiple correct values in Bash?

I have the following piece of Bash script: function get_cms { echo "input cms name" read cms cms=${cms,,} if [ "$cms" != "wordpress" && "$cms" != "meganto" && "$cms" != "typo3" ]; then get_cms fi } But no matter what I…
eagle00789
  • 1,211
  • 2
  • 8
  • 6
108
votes
4 answers

How would you compare jQuery objects?

So I'm trying to figure out how to compare two jQuery objects, to see if the parent element is the body of a page. here's what I have: if ( $(this).parent() === $('body') ) ... I know this is wrong, but if anybody understands what I'm getting at,…
Kyle Hotchkiss
  • 10,754
  • 20
  • 56
  • 82
105
votes
4 answers

Getting "command not found" error while comparing two strings in Bash

My whole script is currently this: #!/bin/sh clear; blanko=""; # Dummy-Variablen variable=Testvariable; if [[$variable == $blanko]]; then echo "Nichts da!" else echo $variable fi and if I enter TestSelect.sh I…
EpsilonAlpha
  • 1,153
  • 2
  • 7
  • 4
103
votes
9 answers

How to compare Enums in TypeScript

In TypeScript, I want to compare two variables containing enum values. Here's my minimal code example: enum E { A, B } let e1: E = E.A let e2: E = E.B if (e1 === e2) { console.log("equal") } When compiling with tsc (v 2.0.3) I get the…
John J. Camilleri
  • 4,171
  • 5
  • 31
  • 41
103
votes
15 answers

How to parse a month name (string) to an integer for comparison in C#?

I need to be able to compare some month names I have in an array. It would be nice if there were some direct way like: Month.toInt("January") > Month.toInt("May") My Google searching seems to suggest the only way is to write your own method, but…
spilliton
  • 3,811
  • 5
  • 35
  • 35
101
votes
7 answers

The right way to compare a System.Double to '0' (a number, int?)

I have this if expression, void Foo() { System.Double something = GetSomething(); if (something == 0) //Comparison of floating point numbers with equality // operator. Possible loss of precision while rounding value …
radbyx
  • 9,352
  • 21
  • 84
  • 127
99
votes
4 answers

Azure DevOps - compare two commits right in the web UI?

This is surely something simple I'm overlooking. In the Azure DevOps web interface (not integrated as part of an IDE), I see how to compare any commit to its parent, but I can't figure out how to compare it to an arbitrary commit. ie, I'm looking…
orion elenzil
  • 4,484
  • 3
  • 37
  • 49
96
votes
14 answers

Using jQuery to compare two arrays of Javascript objects

I have two arrays of JavaScript Objects that I'd like to compare to see if they are the same. The objects may not (and most likely will not) be in the same order in each array. Each array shouldn't have any more than 10 objects. I thought jQuery…
Matt
  • 23,363
  • 39
  • 111
  • 152
95
votes
2 answers

How to check if two data frames are equal

Say I have large datasets in R and I just want to know whether two of them they are the same. I use this often when I'm experimenting different algorithms to achieve the same result. For example, say we have the following datasets: df1 <-…
Waldir Leoncio
  • 10,853
  • 19
  • 77
  • 107
92
votes
1 answer

Relationship and difference between HAL and HATEOAS

HATEOAS (Hypermedia as the Engine of Application State) and HAL (Hypertext Application Language) seem to be related but are not exactly the same. What is the relationship and difference between HATEOAS and HAL?
Lee Chee Kiam
  • 11,450
  • 10
  • 65
  • 87
90
votes
5 answers

std::string comparison (check whether string begins with another string)

I need to check whether an std:string begins with "xyz". How do I do it without searching through the whole string or creating temporary strings with substr().
jackhab
  • 17,128
  • 37
  • 99
  • 136
90
votes
9 answers

Compare/Difference of two arrays in Bash

Is it possible to take the difference of two arrays in Bash. What is a good way to do it? Code: Array1=( "key1" "key2" "key3" "key4" "key5" "key6" "key7" "key8" "key9" "key10" ) Array2=( "key1" "key2" "key3" "key4" "key5" "key6" ) Array3…
Kiran
  • 8,034
  • 36
  • 110
  • 176
88
votes
3 answers

How to compare LocalDate instances Java 8

I am writing an app that needs to be quite accurate in dates and I wonder how can I compare LocalDate instances.. for now I was using something like: LocalDate localdate1 = LocalDate().now(); LocalDate localdate2 =…
azalut
  • 4,094
  • 7
  • 33
  • 46
84
votes
10 answers

Tool to compare large numbers of PDF files?

I need to compare large count of PDF files for it optical content. Because the PDF files was created on different platforms and with different versions of the software there are structural differences. For example: the chunking of text can be…
Horcrux7
  • 23,758
  • 21
  • 98
  • 156
82
votes
11 answers

How to compare Go errors

I have an error value which when printed on console gives me Token is expired How can I compare it with a specific error value? I tried this but it did not work: if err == errors.New("Token is expired") { log.Printf("Unauthorised: %s\n",…
codec
  • 7,978
  • 26
  • 71
  • 127