Skip to main content
Code Review

Return to Question

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

In C#, I could check if any of the nested List collection has a value. Example of such structure [Check a List<List[]> contains a value using Linq][1]

List<int> a= new List<int>(){ 2, 2, 3, 4, 5};
List<int> b= new List<int>() { 2, 2, 2, 6 };
List<List<int>[]> c = new List<List<int>[]>();
c.Add(new[]{a,b});

// checking if the value is in any of the collections. for example, this will result to 2
var result = c.SelectMany(x => x).SelectMany(x => x).Any(p => p == 2);

but since I'm exploring the LINQ capabilities in node js , I decided to extend this to an Array of Arrays

var data= [[2, 2, 3, 4, 5],[2, 2, 2, 6], [9], [13, 1,1,90]];
var LINQ = require('node-linq').LINQ;
var resultI=new LINQ(data).Any(function(row)
{
 return checkElement(row);
});
 console.log(resultI);
function checkElement(array)
 { 
 for(var i = 0 ; i< array.length; i++)
 { 
 if(array[i]== 19){
 return true;
 }
 }
 }

Note: I installed the LINQ module using
npm install https://github.com/wearefractal/node-linq/tarball/master

Can this be improved? please any suggestions will be quite appreciated. [1]: http://stackoverflow.com/questions/38401836/check-a-listlistint-contains-a-value-using-linq https://stackoverflow.com/questions/38401836/check-a-listlistint-contains-a-value-using-linq

In C#, I could check if any of the nested List collection has a value. Example of such structure [Check a List<List[]> contains a value using Linq][1]

List<int> a= new List<int>(){ 2, 2, 3, 4, 5};
List<int> b= new List<int>() { 2, 2, 2, 6 };
List<List<int>[]> c = new List<List<int>[]>();
c.Add(new[]{a,b});

// checking if the value is in any of the collections. for example, this will result to 2
var result = c.SelectMany(x => x).SelectMany(x => x).Any(p => p == 2);

but since I'm exploring the LINQ capabilities in node js , I decided to extend this to an Array of Arrays

var data= [[2, 2, 3, 4, 5],[2, 2, 2, 6], [9], [13, 1,1,90]];
var LINQ = require('node-linq').LINQ;
var resultI=new LINQ(data).Any(function(row)
{
 return checkElement(row);
});
 console.log(resultI);
function checkElement(array)
 { 
 for(var i = 0 ; i< array.length; i++)
 { 
 if(array[i]== 19){
 return true;
 }
 }
 }

Note: I installed the LINQ module using
npm install https://github.com/wearefractal/node-linq/tarball/master

Can this be improved? please any suggestions will be quite appreciated. [1]: http://stackoverflow.com/questions/38401836/check-a-listlistint-contains-a-value-using-linq

In C#, I could check if any of the nested List collection has a value. Example of such structure [Check a List<List[]> contains a value using Linq][1]

List<int> a= new List<int>(){ 2, 2, 3, 4, 5};
List<int> b= new List<int>() { 2, 2, 2, 6 };
List<List<int>[]> c = new List<List<int>[]>();
c.Add(new[]{a,b});

// checking if the value is in any of the collections. for example, this will result to 2
var result = c.SelectMany(x => x).SelectMany(x => x).Any(p => p == 2);

but since I'm exploring the LINQ capabilities in node js , I decided to extend this to an Array of Arrays

var data= [[2, 2, 3, 4, 5],[2, 2, 2, 6], [9], [13, 1,1,90]];
var LINQ = require('node-linq').LINQ;
var resultI=new LINQ(data).Any(function(row)
{
 return checkElement(row);
});
 console.log(resultI);
function checkElement(array)
 { 
 for(var i = 0 ; i< array.length; i++)
 { 
 if(array[i]== 19){
 return true;
 }
 }
 }

Note: I installed the LINQ module using
npm install https://github.com/wearefractal/node-linq/tarball/master

Can this be improved? please any suggestions will be quite appreciated. [1]: https://stackoverflow.com/questions/38401836/check-a-listlistint-contains-a-value-using-linq

edited tags
Link
200_success
  • 145.6k
  • 22
  • 190
  • 479
Source Link
Tolani
  • 2.5k
  • 7
  • 31
  • 49

Check if an Array of Arrays contains a value in node js

In C#, I could check if any of the nested List collection has a value. Example of such structure [Check a List<List[]> contains a value using Linq][1]

List<int> a= new List<int>(){ 2, 2, 3, 4, 5};
List<int> b= new List<int>() { 2, 2, 2, 6 };
List<List<int>[]> c = new List<List<int>[]>();
c.Add(new[]{a,b});

// checking if the value is in any of the collections. for example, this will result to 2
var result = c.SelectMany(x => x).SelectMany(x => x).Any(p => p == 2);

but since I'm exploring the LINQ capabilities in node js , I decided to extend this to an Array of Arrays

var data= [[2, 2, 3, 4, 5],[2, 2, 2, 6], [9], [13, 1,1,90]];
var LINQ = require('node-linq').LINQ;
var resultI=new LINQ(data).Any(function(row)
{
 return checkElement(row);
});
 console.log(resultI);
function checkElement(array)
 { 
 for(var i = 0 ; i< array.length; i++)
 { 
 if(array[i]== 19){
 return true;
 }
 }
 }

Note: I installed the LINQ module using
npm install https://github.com/wearefractal/node-linq/tarball/master

Can this be improved? please any suggestions will be quite appreciated. [1]: http://stackoverflow.com/questions/38401836/check-a-listlistint-contains-a-value-using-linq

default

AltStyle によって変換されたページ (->オリジナル) /