Questions tagged [comparison]

Questions about data comparison and efficient ways to accomplish it. Please avoid using this tag for generic (meta) comparison of two issues or concepts.

Questions about data comparison and efficient ways to accomplish it, e.g.: "Which is the fastest algorithm to compare two recordsets and decide which one has more palindromes?", or "What is the fastest way to compare two strings and say if they have more than Y characters in common?"

There are generally six basic "comparison operators": less than, <; less than or equal to, <=; equal to, ==; not equal to, !=; greater than or equal to, >=; and greater than, >.

8118 questions
3
votes
2 answers

Compare two arrays and present intersections/differences in a github-style

I have two arrays which are sorted alphabetically. Each array contains unique values, but some values will be shared between the two arrays. Sample arrays: $src = ["apple", "cherry", "grape", "lemon", "orange", "strawberry"]; $dst = ["apple",…
Ivan
  • 2,463
  • 6
  • 39
  • 51
3
votes
1 answer

Optimize VBA Script to Combine and Consolidate

I am working on optimizing this script since I am working with two large (~1M rows) worksheets, each and think my code is inefficient and takes way too long to run and wondering if I can redo it to make it faster. These are the steps: Combine Excel…
Ari Monger
  • 71
  • 5
3
votes
2 answers

Typescript Partial interface odd behavior

I ran across some code that looked completely wrong in a repo I'm working on. Below is an example of what I came across. interface Car { make: string model: string } type SomeType = Partial const car: SomeType = {} if (car ===…
haymez
  • 215
  • 1
  • 8
3
votes
4 answers

Am I going crazy with the Perl string comparison operator? Debug log included

I must be missing something about variable assignment or string comparison. I have a script that's going through a tab-separated file. Unless one particular value in a row is "P", I want to skip to the next line. The code looks like: 1 print…
lcheng
  • 31
  • 2
3
votes
1 answer

How do I sort a slice of slices of something (how do I compare two slices) in Go

In Go is possible to compare two strings: package main func main() { println("ab" > "ba") println("ab" < "ba") } false true Program exited. https://go.dev/play/p/svkLf6R84SC How do I perform a similar operation on two slices? e.g.…
eNV25
  • 73
  • 1
  • 7
3
votes
3 answers

golang why comparing two variables pointing to struct behaves differently?

I have created two instances of same struct, Confused by the output when I compare two variables point to instances of struct. package main import "fmt" type Person struct { name string } func main() { p1 := &Person{name: "guru"} p2 :=…
Mithun Kumar
  • 595
  • 1
  • 9
  • 18
3
votes
2 answers

Haskell list of tuples vs tuple comparrison

I'm playing with my first non-trivial (in my eyes) attempt at something in Haskell. I'm probably going to ask questions about each part to compare my coming-from-long-term-relationship-with-c-like-languages attempt to what…
user49011
  • 523
  • 1
  • 3
  • 10
3
votes
1 answer

Is "less than" for rational numbers decideable in Coq?

In the Coq standard library, the "less than" relation is decidable for the natural numbers (lt_dec) and for the integers (Z_lt_dec). When I search however (Search ({ _ _ _ } + {~ _ _ _ })) I can't find a Q_le_dec or Qle_dec for the rationals, only…
LogicChains
  • 4,332
  • 2
  • 18
  • 27
3
votes
3 answers

Why is UUID#compareTo incompatible with RFC 4122?

Overview Javas UUID class implements Comparable. But the order it implements appears to be incompatible with the specificiation given in RFC 4122. In particular, it is inconsistent with the natural order implied by its string representation…
Pedro Borges
  • 1,568
  • 1
  • 14
  • 25
3
votes
4 answers

C# Comparison operators not supported for type Dictionary

I get a dictionary and i want to get the matching database entries for the key field in the dictionary. So the code below gets all database fields that equals the data in the dictionary.keys. So far so good. Now when i loop it and i try to get the…
Patrick
  • 5,442
  • 9
  • 53
  • 104
3
votes
1 answer

Why does JavaScript `Intl.Collator.prototype.compare()` method yield different result than traditional UTF-16 comparison for special characters?

Today, I stumbled onto a weird issue with the JavaScript / ECMAScript Internationalization API that I can't find a suitable explanation anywhere. I am getting different results when comparing two specific characters - the forward-slash (/) and the…
3
votes
1 answer

PHP 7.4 string comparison

Can somebody explain why in the first example below the comparison is returning false? In the second example, you can see that just changing the first character it will return true instead. What am I missing? (1 !=…
s7a8m
  • 51
  • 2
3
votes
4 answers

Detecting the "actual" end of an array in PHP

Given I have an array as follows: $array = array('a', 'b', 0, 'c', null, 'd'); Now, I can iterate through it easily with foreach of course: foreach($array as $value){ var_dump($value); } And all is fine and well. However, if I want to do a…
Dan Lugg
  • 20,192
  • 19
  • 110
  • 174
3
votes
3 answers

Pandas comparing a DataFrame against a ground truth DataFrame

I have a DataFrame that contains a list of unordered project IDs and their respective leaders. I want to compare a new dataframe's values with the ground truth to verify that all the project IDs in the new data frame are both; in the ground truth…
iby.helmy
  • 190
  • 8
3
votes
3 answers

How to properly check object types in Python?

Problem: I have to check that the a returned value is a Python dictionary. Q1. Which of these options is the proper way to do this? type(x) == dict type(x) == type(dict) isinstance(d, dict) Then there are the other variants using is operator…
Paolo
  • 20,112
  • 21
  • 72
  • 113
1 2 3
99
100