• + 0 comments

    my solution in Javascript:

    if the count of odd numbers are odd it should return 'NO', and...

    function fairRations(B) {
        let count = 0;
        if (B.filter((v) => v % 2 == 1).length % 2 == 1) {
            return "NO";
        } else {
            B.forEach((v, i) => {
                if (v % 2 == 1) {
                    B[i]++;
                    B[i + 1]++;
                    count += 2;
                }
            });
        }
        return count;
    }