LINQ and their ES6 Equivalents
I've started working on a new client recently, where the tech stack on the front-end is React. This means I've started delving into the deep, dark world of JavaScript* (or ECMAScript, if you prefer).
A mate at work flicked through a neat little table that outline common LINQ functions in use throughout C#, and their ES6 equivalents. So I thought I'd take a second to blog (woooo, look at me all blogging and stuff!) about it, before I forget.
LINQ | ES6 |
Any | some |
All | every |
Aggregate | reduce |
Select | map |
Where | filter |
This shiny little nugget of knowledge came about as I was kludging my way around a for
loop in a function, iterating over an array of objects, checking if a value existed. A colleague informed me "uhh why don't you just some
". You can even invoke it using an arrow function:
myArray.some(val => val === mySuperAwesomeValue)
Neat!
I found it interesting how in seeing these direct comparisons helped me demystify some of the language or terminology I've seen scattered around JavaScript, which in all honesty I'd found a bit intimidating so far.
This lead to some interesting discussions on LINQ and some of the lesser (to me, at least) known functions in JavaScript land, which led to Ben showing me this handy little table.
If you're interested in functional programming within the realm of JavaScript, I was also linked to this little gem, which is a great resource collating the various entries into functional programming that JavaScript has made. Thanks Tod!
Got another cool function I'm missing? Hit me up on the twitters!
Night all!
*In all seriousness, if you are doing a project that involves JavaScript, I'd recommend checking out JavaScript: The Good Parts. This book gave me a new appreciation of the unexpected power of JavaScript and enabled me to hate it a little less :)
[Edit 14-Jul-2017]: I've just been informed these methods have actually been around since ES5. Just goes to show how long it's been since I've really done anything serious in JavaScript. Thanks Aaron!