leandro713
leandro713

Reputation: 1408

Why Ramdajs.filter() works in my code and Ramdajs.find() not?

I have a js object like

var storage = [
1:{"index":1, "label": abc, "value": 33},
2:{"index":2, "label": def, "value": 43},
etc.
];

so, now i need to extract a given inner object given a "label" value

i find working:

R.filter( R.propEq( "label", labelname ), storage )

but find() isn't working:

R.find( R.propEq( 'label', labelname ))( storage )

can anybody enlighten me about this?

Upvotes: 0

Views: 99

Answers (1)

Scott Sauyet
Scott Sauyet

Reputation: 50807

I'm a little confused by your data structure. Doing it like this, both filter and find seems to work fine:

var abc = "ABC", def = "DEF";

var storage = [
  {"index":1, "label": abc, "value": 33},
  {"index":2, "label": def, "value": 43},
  {"index":1, "label": abc, "value": 53},
];

var labelname = abc;

R.filter( R.propEq( "label", labelname ), storage );
//=> [{"index":1,"label":"ABC","value":33},{"index":1,"label":"ABC","value":53}]
R.find( R.propEq( "label", labelname ), storage );
//=> {"index":1,"label":"ABC","value":33}

You can see this in action on the Ramda REPL.

What are those extra index numbers in the beginning of your records?:

var storage = [
1:{"index":1, "label": abc, "value": 33},
^
 \---- What's this?

Upvotes: 1

Related Questions