How to Implement LINQ methods in JavaScript – Part 8

April 28, 2018
💫 Originally posted here. Broken? Let me know ~

Photo by Pau Casals on Unsplash
LINQ methods (All, Contains, SequenceEqual) in this article  are somehow related in a way that they are predicates (returns true or false).

Here are the methods covered so far.

  1. Part 1 〰️ Select, Aggregate, Where, OrderBy (Ascending, Descending)
  2. Part 2 〰️ Any, Distinct, Concat, SelectMany
  3. Part 3 〰️ Reverse, Zip, Min/Max
  4. Part 4 〰️ Union, Intersect, Except
  5. Part 5 〰️ Sum, Average, Count
  6. Part 6 〰️ First, Last, DefaultIfEmpty, Skip, Take
  7. Part 7 〰️ Empty, Repeat, Range
  8. Part 8 〰️ All, Contains, SequenceEqual

🔴 Overview

In this article, I will cover following methods.

LINQ MethodsJavaScript MethodsGo to example

The sample collections used in this part are shown as below.


🔴 Examples

🔸 All

JavaScript has a method called Array#every, which works the same way as All does.


every is more flexible as the callback is also passed an index.

array#every syntax

🔸 Contains

There are so many ways implement contains but i used some as it short circuits (returns as soon as a condition is met).


OrderEqualityComparer object instance simply checks if two objects are the same by an ID. JavaScript version simply passes a callback which does the same.

🔸 SequenceEqual

You can use every here to check if two sequences are the same as every passes an index of current element to the callback.


🔴 Closing Remark

I hope this article can serve as a cheat sheet (that’s how I started this series).

Please let me know should you find any errors or improvements I can make to the codes.
The full source code and instructions on how to run them are on GitHub.