Ramda.js R.symmetricDifference() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Relation

Definition

Ramda’s R.symmetricDifference() answers a set question: which unique items sit in either list, but not in both? You pass two lists. You get back a new array: leftovers from list1 that are missing from list2, then leftovers from list2 that are missing from list1, with duplicates collapsed. Equality is R.equals, so objects and nested arrays match by value, not by identity. Need only first-minus-second? That is R.difference. Need items in both lists? That is R.intersection. Need to drop values from a list while keeping leftover duplicates? That is R.without. Need a custom match instead of R.equals? That is R.symmetricDifferenceWith. Lodash _.xor looks similar but uses SameValueZero, so two {a: 1} objects with different identities do not match.

The official samples are the whole idea. Shared 3 and 4 drop. [1,2,3,4] xor [7,6,5,4,3] is [1,2,7,6,5]. Swap the lists and you get [7,6,5,1,2] — the SET of values is the same (1,2,5,6,7), but the ARRAY order follows whichever list you pass first. Previous helper is R.sortWith. Next is R.symmetricDifferenceWith.

Syntax

Call R.symmetricDifference. Start with this line.

Ramda
R.symmetricDifference(list1, list2)
CallWhat it does
R.symmetricDifference(list1, list2)Primary signature.
R.symmetricDifference(...)Call the relation helper.

Prefer import { symmetricDifference } from "ramda" when you want a named import.

Library declarations
Ramda
R.symmetricDifference(list1, list2)

Parameters

ParameterDescription
list1Required. Array. The first list. Unique leftovers from this list appear first. Not mutated.
list2Required. Array. The second list. Unique leftovers from this list are appended. Membership uses R.equals.

Return Value

Return ValueDescription
ArrayA new array: the set of elements in list1 or list2, but not both. Duplicates appear once. Empty leftover → [].

Ramda Examples

📚 Getting Started

The official Ramda samples: numbers in both directions, then first-minus-second vs either-not-both on the same lists.

Example 1 — Official Number Samples

Shared 3 and 4 drop. Leftovers from list1 keep first-appearance order, then leftovers from list2. Swap the lists and the array order changes even though the set of values is the same.

Ramda
R.symmetricDifference([1, 2, 3, 4], [7, 6, 5, 4, 3]);
//=> [1, 2, 7, 6, 5]

R.symmetricDifference([7, 6, 5, 4, 3], [1, 2, 3, 4]);
//=> [7, 6, 5, 1, 2]
Try It Yourself

How It Works

That is the docs sample from ramdajs.com. In the first call, 1 and 2 are missing from the second list; 7, 6, and 5 are missing from the first. Shared 3 and 4 drop. Reverse the lists and membership is still 1,2,5,6,7, but the leftover order starts from the other tray.

Example 2 — vs R.difference on the Same Lists

difference keeps only the first leftover. symmetricDifference concatenates both leftovers.

Ramda
R.difference([1, 2, 3, 4], [7, 6, 5, 4, 3]);
//=> [1, 2]

R.symmetricDifference([1, 2, 3, 4], [7, 6, 5, 4, 3]);
//=> [1, 2, 7, 6, 5]
Try It Yourself

How It Works

R.difference is first-minus-second: [1,2]. XOR appends the second leftover [7,6,5]. Previous cousin: R.difference.

📈 Practical Patterns

Shared set vs XOR leftovers, objects compared by value, then deduping plus a curried leftover for team pipelines.

Example 3 — vs R.intersection

intersection is both. XOR is neither-shared: the official leftovers instead of the official shared pair.

Ramda
R.intersection([1, 2, 3, 4], [7, 6, 5, 4, 3]);
//=> [4, 3]

R.symmetricDifference([1, 2, 3, 4], [7, 6, 5, 4, 3]);
//=> [1, 2, 7, 6, 5]
Try It Yourself

How It Works

The official intersection of those lists is [4,3] — the shared pair. XOR drops that pair and keeps everything else. Previous cousin: R.intersection.

Example 4 — Objects with R.equals

{a: 1} in the first list matches {a: 1} in the second even though they are different object identities. Leftovers from both sides stay.

Ramda
R.symmetricDifference([{ a: 1 }, { b: 2 }], [{ a: 1 }, { c: 3 }]);
//=> [{ b: 2 }, { c: 3 }]
Try It Yourself

How It Works

Membership uses R.equals, not ===. {a: 1} is in both, so it drops. {b: 2} is only in list1; {c: 3} is only in list2. Lodash _.xor would keep all four objects here because SameValueZero does not deep-compare records. Previous helper is R.equals.

Example 5 — Deduping and Curried Leftover

Duplicates collapse. Fill the first list and you get a function of the second: const onlyInOne = R.symmetricDifference(teamA).

Ramda
R.symmetricDifference([1, 1, 2, 2, 3], [3, 4, 4]);
//=> [1, 2, 4]

const xorSet = R.symmetricDifference([1, 2, 3]);
xorSet([3, 4]);
//=> [1, 2, 4]

const teamA = [1, 1, 2, 3];
const teamB = [3, 4, 4];
const onlyInOne = R.symmetricDifference(teamA);
onlyInOne(teamB);
//=> [1, 2, 4]
Try It Yourself

How It Works

Each difference is already a set, so extra copies of 1 and 4 collapse. Because the helper is arity 2, filling one argument leaves a leftover. R.without([3], [1,1,2,2,3]) would keep leftover copies; XOR never does. Boolean analog for two flags: R.xor.

Browser Support

R.symmetricDifference() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.

✓ Ramda 0.19.0+ · Any JS runtime

Ramda.js R.symmetricDifference()

Load Ramda 0.19.0 or later via CDN or npm, then call R.symmetricDifference with two lists. No extra browser API is required.

100% With Ramda 0.19.0+
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
R.symmetricDifference() Universal

Bottom line: Safe in any project that includes Ramda 0.19.0 or later. Use a CDN build such as ramda.min.js in the browser or install ramda from npm for Node. These labs use [email protected].

Frequently Asked Questions

R.symmetricDifference(list1, list2) returns the set of all elements contained in the first or second list, but not both. Duplicates are dropped. Type: [*] → [*] → [*]. Arity 2, curried. Added in v0.19.0.
R.symmetricDifference([1,2,3,4], [7,6,5,4,3]) is [1,2,7,6,5]. Swap the lists and you get [7,6,5,1,2]. Shared 3 and 4 drop. Leftovers from list1 keep first-appearance order, then leftovers from list2.
difference is only first-minus-second. intersection is items in both lists. symmetricDifference concatenates both leftovers (XOR / either-not-both). without filters list2 and can keep leftover duplicates; xor is a unique set. Lodash _.xor is similar but uses SameValueZero, not deep equals.
No. Objects and arrays use R.equals (value equality), like R.difference. Two {a: 1} records match even when they are different object identities.
The SET of values stays the same (same membership). The ARRAY order changes: leftovers from the first argument, then leftovers from the second. So it is not commutative as arrays.
No. R.symmetricDifference is a stable Ramda relation helper from v0.19.0. It is not deprecated, experimental, or non-standard.

Continue to R.symmetricDifferenceWith()

Learn either-not-both leftovers with a comparator you pick — eqBy, a custom pair test, or R.equals.

R.symmetricDifferenceWith() Method →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful