$ LINQ-a javascript LINQ Library

Source: Internet
Author: User
Project Description
$ LINQ is a javascript version of. Net's LINQ to objects, with some query operations stored red by morelinq (an extension to LINQ to objects ).
What is $ LINQ?

$ LINQ is an implementation. net LINQ to objects for JavaScript. it implements most of the corresponding. net LINQ to objects methods. it also implements some methods should red by morelinq (http://code.google.com/p/morelinq ). $ LINQ will work with arrays and jquery collections. $ LINQ can also generate values from a numerical range, as an item repeated a given number of times, and from Regexp match results.
Some of the LINQ to objects methods implemented

    • Select
    • Selectworkflow
    • Where
    • Orderby
    • Thenby
    • Distinct
    • Groupby
    • Groupjoin
    • Join
    • Except
    • Union
    • Intersect
    • Take/takewhile/takeuntil
    • Skip/skipwhile/skipuntil
Examples

A simple example of breaking up a sequence of numbers into even and odd Arrays:

 
VaRList = $ LINQ ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);VaREvens = List. Where (Function(X ){ReturnX % 2 = 0;}). toarray ();VaROdds = List. Where ("X => X % 2 = 1"). Toarray ();

Ordering a list of people:

VaRPeople = [{first:"Jason", Last:"Bourne"}, {First:"Gandalf", Last:"The grey"}, {First:"John", Last:"Smith"}, {First:"Albert", Last:"Smith"}];VaRResults = $ LINQ (people). orderby (Function(X ){ReturnX. Last;}). thenby ("X => X. First"). Toarray ();

Using an inner join:

 VaR Users = [{Username: "Asmith" , Domain:"North_america" }, {Username: "Tmcfarland" , Domain: "Europe" }, {Username: "Cdeckard" , Domain: "Nort_america" }]; VaR Groups = [{User: "Asmith" , Groupname: "Base_users" }, {User: "Tmcfarland" , Groupname: "Admins" }, {User: "Cdeckard" , Groupname:"Base_users" }, {User: "Cdeckard" , Groupname: "Testers" }]; VaR Results = $ LINQ (users). Join (groups, Function (X ){ Return X. Username ;}, // Key for 'users'      "X => X. User" , // Key for 'groupup'      Function (Outer, inner) // Function to generate results {Return   "User :" + Outer. username + ", Domain :" + Outer. Domain + ", Group :" + Inner. groupname ;}, "(X, y) => X. tolowercase () = Y. tolowercase ()" ); // Compare keys case-insensitively 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.