Linqjs Tutorial #01 - Nodejs with Lambda Expression (Install, Sum, Avg, Min, Max, Select)

in #utopian-io6 years ago

linqjs.png

Repository

https://github.com/mihaifm/linq

What Will I Learn?

  • You will learn about linqjs.
  • You will learn how to install linqjs with your project.
  • You will learn how to summation values using linqjs.
  • You will learn how to average values using linqjs.
  • You will learn how to minimum values using linqjs.
  • You will learn how to maximum values using linqjs.
  • You will learn how to select specific column values using linqjs.

Requirements

  • Node.JS
  • Basic knowledge of Javascript
  • Any suitable code editor

Difficulty

  • Basic/Intermediate

Tutorial Contents

1. About linqjs

LINQ (Language Integrated Query) is query syntax in C# and VB.NET for saving and retrieving data from different sources. Linqjs is a javascript implementation of the .NET LINQ library. Which allows saving and retrieving data from json or array. It contains all the origial .NET methods with some extra methods.

2. Install

npm install linq

At the start of the javascript file add this line.

const rlinq = require('linq');

This line will include linqjs package to the script so we can work with it.

Declare an array which will be used on our following steps of tutorial

products.png
We have declared an array of products. which contains products id, name and its price.

var products = [
{ "id": 100, "name": "Pendrive", "price": 500 },
{ "id": 101, "name": "Ram", "price": 1000 },
{ "id": 102, "name": "Motherboard", "price": 5000 },
{ "id": 103, "name": "Keyboard", "price": 450 }
]

3. Summation

Our target is to summation the total price of the products. Our following single line of code using linqjs will summarize the total price of products.

var totalprice = rlinq.from(products).sum("$.price");

Explanation :

  • rlinq is the references of linqjs
  • we have passed products list on the parameter of from function
  • we mentioned price to sum by passing $.price(lambda expression) as a parameter of sum function
  • this will return the summarize price of products

4. Average

Our target is to calculate the average price of the products. Our following single line of code using linqjs will return the average price of the products.

var averageprice = rlinq.from(products).average("$.price");

Explanation :

  • rlinq is the references of linqjs
  • we have passed products list on the parameter of from function
  • we mentioned price to calculate average by passing $.price(lambda expression) as a parameter of average function
  • this will return the average price of products

5. Minimum

Our target is to find out minimum price of the products. Our following single line of code using linqjs will return the minimum price.

var minimumprice = rlinq.from(products).min("$.price");

Explanation :

  • rlinq is the references of linqjs
  • we have passed products list on the parameter of from function
  • we mentioned price to find minimum by passing $.price(lambda expression) as a parameter of min function
  • this will return the minimum price of products

6. Maximum

Our target is to find out maximum price of the products. Our following single line of code using linqjs will return the maximum price.

var maximumprice = rlinq.from(products).max("$.price");

Explanation :

  • rlinq is the references of linqjs
  • we have passed products list on the parameter of from function
  • we mentioned price to find maximum by passing $.price(lambda expression) as a parameter of max function
  • this will return the maximum price of products

7. Select

Our target is to select all products name in a array. Our following single line of code using linqjs will return all products name.

var productName = rlinq.from(products).select("$.name").toArray();

Explanation :

  • rlinq is the references of linqjs
  • we have passed products list on the parameter of from function
  • we mentioned name to find maximum by passing $.name(lambda expression) as a parameter of select function
  • toArray function will make a list of product name from original product list

Proof of Work Done

Tutorial Code
GitHub: https://github.com/touhidalam69/linqjsTutorial

Sort:  

Great tutorial thanks for sharing.

Thanks for your complement

Thank you for your contribution.
While I liked the content of your contribution, I would still like to extend few advices for your upcoming contributions:

  • Resources: Put more extra resources.
  • Structure of the tutorial: Improve the structure of the tutorial.
  • Avoid repetition: Frequent use of words or phrases makes reading the tutorial more annoying.

Looking forward to your upcoming tutorials.

See in this link an example of a good tutorial.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Hello, @portugalcoin59,
Thanks for your nice observation about my tutorial post. Actually this is my first contribution post on this category. I will keep it mind all of your advices on my following contribution.

Thanks again ☺☺☺

In addition to @portugalcoin's notes, your tutorial does not really capture a proper structure nor content of a tutorial.

  • Simply stating aggregate functions such as sum/avg, and copy/pasting the same comment over and over does not stand as a proper tutorial
  • You did not provide any real life useful scenario of utilizing those functions
  • You did not provide any screenshots to capture your proper work and result of work done.
  • Your code (github) simply defined variables, you did not even print the result
  • What does this even mean: "we mentioned name to find maximum by passing $.name(lambda expression) as a parameter of select function" basically a copy paste error from sentence above?
    Please work on providing better quality tutorials in the future.

Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Hi @mcfarhat66,
Thanks for asking me about my mistakes on this tutorial post.
I will be aware in future contribution.
Thanks again 😌😌😌

Coin Marketplace

STEEM 0.25
TRX 0.11
JST 0.032
BTC 63478.09
ETH 3067.28
USDT 1.00
SBD 3.81