Here are the series covered so far.
In this post, I will cover following methods.
And I will try to stick to using Vanilla JS.
The sample collection used in this part is the same as the previous one but I will list them again.
⚡ NOTE ⚡ : In all of examples,
In C#, it’s statically imported as
using static System.Console.
console.log declared as
const WriteLine = console.log.
someis used instead of
Yearis retrieved with a method call ,
The results for all three methods are the same.
filter to filter out records that does not show up as the first element in the list (Please refer to this StackOverflow question for more information for implementation details).
distinctDemo2 uses a Set object (sets by definition stores only unique values and is available from ES6) to store unique values in it, and uses a spread syntax to convert the
Set object instance to an array (You could use another new ES6 addition, Array.from if you think it’s not readable enough, as shown below).
⚠️ WARNING: Beware of super contrived example used in this demo.
Syntax is exactly the same 😄(except capitalization), so moving right along to the next example⤵️, SelectMany.
As you can see, the result is exactly the same as the one in Concat demo.
SelectMany basically flattens multiple collections into a single one, while
Spread syntax in ES6 is used to flatten all arrays into a single one.
🔴 Closing Remark
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.
(Same as the first part as demos are added onto existing source code)