These are chat archives for ramda/ramda

16th
Aug 2016
zeecher Game
@zeecher
Aug 16 2016 06:38

Hi everyone, can you help me to optimize my solution. I think there should be more elegant ways to solve this type of questions

  const opponents = [
        {
            "id": 35,
            "name": "Ronaldinho"
        },
        {
            "id": 233,
            "name": "Zidane"
        },
        {
            "id": 9772,
            "name": "Messi"
        },
        {
            "id": 78426,
            "name": "Ronaldo"
        },
        {
            "id": 104211,
            "name": "Runey"
        },
        {
            "id": 170654,
            "name": "Fabregas"
        },
        {
            "id": 185602,
            "name": "Mata"
        },
        {
            "id": 185603,
            "name": "Robin"
        }
    ]

const matches = [
    {
        "id": 1122986,
        "opp1": 35,
        "opp2": 233,
        "match_date": 1471327200,
        "match_no": 1,

    },
     {
        "id": 1122986,
        "opp1": 9772,
        "opp2": 78426,
        "match_date": 1471327200,
        "match_no": 2,

    },  
    {
        "id": 1122986,
        "opp1": 104211,
        "opp2": 170654,
        "match_date": 1471327200,
        "match_no": 3,

    },  
    {
        "id": 1122986,
        "opp1": 185602,
        "opp2": 185603,
        "match_date": 1471327200,
        "match_no": 4,

    },
]


const revolveMatch = R.curry((opponents, match) => ({

     id: R.prop('id', match)
    ,no: R.prop('match_no', match)
    ,date: R.prop('match_date', match)
    ,opponentOne: R.prop('name', R.find(R.propEq('id', R.prop('opp1', match)))(opponents))
    ,opponentTwo: R.prop('name', R.find(R.propEq('id', R.prop('opp2', match)))(opponents))
}));

   //Assign match opponents 
   R.map(match => revolveMatch(opponents)(match))(matches);

/**
[
 {"date": 1471327200, "id": 1122986, "no": 1, "opponentOne": "Ronaldinho", "opponentTwo": "Zidane"},
 {"date": 1471327200, "id": 1122986, "no": 2, "opponentOne": "Messi", "opponentTwo": "Ronaldo"}, 
 {"date": 1471327200, "id": 1122986, "no": 3, "opponentOne": "Runey", "opponentTwo": "Fabregas"}, 
 {"date": 1471327200, "id": 1122986, "no": 4, "opponentOne": "Mata", "opponentTwo": "Robin"}
]
*/

http://goo.gl/EzobSX

Martin Broder
@mrtnbroder
Aug 16 2016 14:06
Is there a way to bypass value needed by R.reduce?
I don't have an inital value
Brad Compton (he/him)
@Bradcomp
Aug 16 2016 14:36
@ram-bot
converge(reduce(add), [head, tail])([1,2,3])
ram-bot
@ram-bot
Aug 16 2016 14:36
6
Brad Compton (he/him)
@Bradcomp
Aug 16 2016 14:38
This begs the question though, what would you want the answer to be if you passed in an empty list?
Drew
@dtipson
Aug 16 2016 17:58
This message was deleted