Monday, June 3, 2024
170
rated 0 times [  177] [ 7]  / answers: 1 / hits: 18596  / 8 Years ago, tue, december 27, 2016, 12:00:00

Ramda REPL example



var portfolio = [{ticker: aa},  {ticker: bb}];

var ticker = {ticker:aa};

var exist = R.find(R.propEq('ticker', ticker), portfolio)

console.log(exist)


Currently this is giving me undefined, however R.propEq should find the matching object by key ticker in port I thought?


More From » functional-programming

 Answers
15

As you say, you can solve it by passing in the key to propEq:



R.find(R.propEq('ticker', 'aa'), port)


Another option is to use the eqProps function, which tests if two objects match for the named key:



R.find(R.eqProps('ticker', ticker), port)


You can see the first or second version in the Ramda REPL.


[#59546] Saturday, December 24, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
michaelashelbieh

Total Points: 303
Total Questions: 139
Total Answers: 97

Location: Suriname
Member since Sun, Oct 17, 2021
3 Years ago
;