Can I do it?

I made this snippet using ramda to check if any value of array A exists in array B if they are flat arrays.

 var hasAtLeastOneTruthValue = ramda.contains(true); var alpha = [1,2,3] var beta = [4,1,7]; var valueOfArrayInArray = ramda.map(function(a_v){ return ramda.contains(a_v, beta); }); console.log(hasAtLeastOneTruthValue(valueOfArrayInArray(alpha))); 

What I don't like is the hardcoded beta inside valueOfArrayInArray . Is it possible to do otherwise so that it is not? Note that I'm not looking for a completely different implementation that has the same effect, but just for understanding is better in this case.

+5
source share
2 answers

You can partially apply contains on the right:

 var valueOfArrayInArray = R.map(R.rPartial(R.contains, beta)) 

Or flip it:

 var valueOfArrayInArray = R.map(R.flip(R.contains)(beta)) 
+6
source

Use binding:

 var hasAtLeastOneTruthValue = ramda.contains(true); var alpha = [1,2,3] var beta = [4,1,7]; function finder(lookup,a_v){ return ramda.contains(a_v, lookup); } var valueOfArrayInArray = ramda.map(finder.bind(null,beta)); console.log(hasAtLeastOneTruthValue(valueOfArrayInArray(alpha))); 
0
source

Source: https://habr.com/ru/post/1203322/


All Articles