create account

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

View this thread on: hive.blogpeakd.comecency.com
· @touhidalam69 ·
$0.14
Linqjs Tutorial #01 - Nodejs with Lambda Expression (Install, Sum, Avg, Min, Max, Select)
![linqjs.png](https://cdn.steemitimages.com/DQmecCSuSwCqMYsfGHVn8Fu8LuRsrPu1EtuDMLqApMnHJa2/linqjs.png)

### Repository
[https://github.com/mihaifm/linq](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](https://cdn.steemitimages.com/DQmYvggfp3uFwhFMcJiyFbYyzRXteUgCe9tE3QmCvGhdaC7/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 : 
- <b>rlinq</b> is the references of <b>linqjs</b>
- we have passed products list on the parameter of <b>from</b> function
- we mentioned <b>price</b> to sum by passing <b>$.price</b>(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 : 
- <b>rlinq</b> is the references of <b>linqjs</b>
- we have passed products list on the parameter of <b>from</b> function
- we mentioned <b>price</b> to calculate average by passing <b>$.price</b>(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 : 
- <b>rlinq</b> is the references of <b>linqjs</b>
- we have passed products list on the parameter of <b>from</b> function
- we mentioned <b>price</b> to find minimum by passing <b>$.price</b>(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 : 
- <b>rlinq</b> is the references of <b>linqjs</b>
- we have passed products list on the parameter of <b>from</b> function
- we mentioned <b>price</b> to find maximum by passing <b>$.price</b>(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 : 
- <b>rlinq</b> is the references of <b>linqjs</b>
- we have passed products list on the parameter of <b>from</b> function
- we mentioned <b>name</b> to find maximum by passing <b>$.name</b>(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](https://github.com/touhidalam69/linqjsTutorial/blob/master/src/01_lambda_Sum_Avarage_Minimum_Maximum_Select.js)
GitHub: [https://github.com/touhidalam69/linqjsTutorial](https://github.com/touhidalam69/linqjsTutorial)
πŸ‘  , , , , , , , , , , , , , , , , ,
properties (23)
authortouhidalam69
permlinklinqjs-tutorial-01-nodejs-with-lambda-expression-install-sum-avg-min-max-select
categoryutopian-io
json_metadata{"tags":["utopian-io","tutorials","javascript","linqjs","nodejs"],"image":["https://cdn.steemitimages.com/DQmecCSuSwCqMYsfGHVn8Fu8LuRsrPu1EtuDMLqApMnHJa2/linqjs.png","https://cdn.steemitimages.com/DQmYvggfp3uFwhFMcJiyFbYyzRXteUgCe9tE3QmCvGhdaC7/products.png"],"links":["https://github.com/mihaifm/linq","https://github.com/touhidalam69/linqjsTutorial/blob/master/src/01_lambda_Sum_Avarage_Minimum_Maximum_Select.js","https://github.com/touhidalam69/linqjsTutorial"],"app":"steemit/0.1","format":"markdown"}
created2018-06-10 16:32:27
last_update2018-06-10 16:32:27
depth0
children6
last_payout2018-06-17 16:32:27
cashout_time1969-12-31 23:59:59
total_payout_value0.125 HBD
curator_payout_value0.016 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,694
author_reputation2,409,777,621,558
root_title"Linqjs Tutorial #01 - Nodejs with Lambda Expression (Install, Sum, Avg, Min, Max, Select)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id60,163,932
net_rshares54,043,991,764
author_curate_reward""
vote details (18)
@mcfarhat ·
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](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  
properties (23)
authormcfarhat
permlinkre-touhidalam69-linqjs-tutorial-01-nodejs-with-lambda-expression-install-sum-avg-min-max-select-20180611t111356688z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["portugalcoin"],"links":["https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2018-06-11 11:14:03
last_update2018-06-11 11:14:03
depth1
children1
last_payout2018-06-18 11:14:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length932
author_reputation150,651,671,367,256
root_title"Linqjs Tutorial #01 - Nodejs with Lambda Expression (Install, Sum, Avg, Min, Max, Select)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id60,279,241
net_rshares3,949,492,369
author_curate_reward""
vote details (1)
@touhidalam69 · (edited)
Hi @mcfarhat66,
Thanks for asking me about my mistakes on this tutorial post. 
I will be aware in future contribution. 
Thanks again 😌😌😌
πŸ‘  
properties (23)
authortouhidalam69
permlinkre-mcfarhat-re-touhidalam69-linqjs-tutorial-01-nodejs-with-lambda-expression-install-sum-avg-min-max-select-20180611t210404995z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"busy","app":"busy/2.4.0"}
created2018-06-11 21:04:09
last_update2018-06-11 21:04:33
depth2
children0
last_payout2018-06-18 21:04:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length136
author_reputation2,409,777,621,558
root_title"Linqjs Tutorial #01 - Nodejs with Lambda Expression (Install, Sum, Avg, Min, Max, Select)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id60,352,031
net_rshares3,576,600,205
author_curate_reward""
vote details (1)
@portugalcoin ·
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: 

- <b>Resources:</b> Put more extra resources.
- <b>Structure of the tutorial:</b> Improve the structure of the tutorial.
- <b>Avoid repetition:</b>Β Frequent use of words or phrases makes reading the tutorial more annoying.

Looking forward to your upcoming tutorials.

See in this <a href="https://steemit.com/utopian-io/@espoem/make-your-posts-look-great-in-steemit-and-busy">link</a> an example of a good tutorial.

Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/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](https://review.utopian.io/result/8/31324323).

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  
properties (23)
authorportugalcoin
permlinkre-touhidalam69-linqjs-tutorial-01-nodejs-with-lambda-expression-install-sum-avg-min-max-select-20180610t224322117z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https://steemit.com/utopian-io/@espoem/make-your-posts-look-great-in-steemit-and-busy","https://join.utopian.io/guidelines","https://review.utopian.io/result/8/31324323","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2018-06-10 22:43:21
last_update2018-06-10 22:43:21
depth1
children1
last_payout2018-06-17 22:43:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,065
author_reputation599,442,230,817,318
root_title"Linqjs Tutorial #01 - Nodejs with Lambda Expression (Install, Sum, Avg, Min, Max, Select)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id60,205,828
net_rshares4,033,079,509
author_curate_reward""
vote details (1)
@touhidalam69 ·
$0.03
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 ☺☺☺
πŸ‘  
properties (23)
authortouhidalam69
permlinkre-portugalcoin-re-touhidalam69-linqjs-tutorial-01-nodejs-with-lambda-expression-install-sum-avg-min-max-select-20180611t205057708z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"busy","app":"busy/2.4.0"}
created2018-06-11 20:51:00
last_update2018-06-11 20:51:00
depth2
children0
last_payout2018-06-18 20:51:00
cashout_time1969-12-31 23:59:59
total_payout_value0.029 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length230
author_reputation2,409,777,621,558
root_title"Linqjs Tutorial #01 - Nodejs with Lambda Expression (Install, Sum, Avg, Min, Max, Select)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id60,350,611
net_rshares11,817,633,318
author_curate_reward""
vote details (1)
@steem0 ·
Great tutorial thanks for sharing.
πŸ‘  
properties (23)
authorsteem0
permlinkre-touhidalam69-linqjs-tutorial-01-nodejs-with-lambda-expression-install-sum-avg-min-max-select-20180610t163504633z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-06-10 16:35:06
last_update2018-06-10 16:35:06
depth1
children1
last_payout2018-06-17 16:35:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length34
author_reputation907,702,232,817
root_title"Linqjs Tutorial #01 - Nodejs with Lambda Expression (Install, Sum, Avg, Min, Max, Select)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id60,164,266
net_rshares1,964,297,792
author_curate_reward""
vote details (1)
@touhidalam69 ·
Thanks for your complement
properties (22)
authortouhidalam69
permlinkre-steem0-re-touhidalam69-linqjs-tutorial-01-nodejs-with-lambda-expression-install-sum-avg-min-max-select-20180611t214627932z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"busy","app":"busy/2.4.0"}
created2018-06-11 21:46:30
last_update2018-06-11 21:46:30
depth2
children0
last_payout2018-06-18 21:46:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length26
author_reputation2,409,777,621,558
root_title"Linqjs Tutorial #01 - Nodejs with Lambda Expression (Install, Sum, Avg, Min, Max, Select)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id60,356,468
net_rshares0