ramda / ramda-fantasy

:ram::sparkles: Fantasy-Land compatible types for easy integration with Ramda.js
MIT License
1.5k stars 95 forks source link

Does Ramda has a function that gets common value from array? #168

Closed VadimZP closed 6 years ago

VadimZP commented 6 years ago

If not (I have not found), maybe you can add something like this?


function commonVal(arr) {
        const sorted = arr.sort();

        let obj = {};

        let tempArray = [];

        sorted.forEach((val, i, arr) => {
            if (arr[i] != arr[i + 1]) {
                tempArray.push(arr[i]);
                obj[tempArray.length] = tempArray;
                tempArray = [];
            } else {
                tempArray.push(arr[i]);
            }
        });

        const numsArr = Object.keys(obj).map(el => +el);

        const getCommon = obj[Math.max(...numsArr)][0];

        return getCommon;
    }
VadimZP commented 6 years ago

Sorry, this is for Ramda, not Ramda-fantasy.