Skip to content

exercise 3 & 4 #3

@nicc

Description

@nicc

We're still working with reduce as the basis for recursive list computation.

exercise 3
Implement myFilter this time. Once again using only a single call to myReduce.

exercise 4
Now do myGroupBy. You're still only allowed to implement it using a single call to myReduce. The function should accept a collection and a function. All items in the collection should be grouped by their return value for that function. The return type should be an object / associative list / hashmap / whatever you want to call it. For example:

myGroupBy([1,2,3,4,5,6], (item) => {
    return ( item & 1 ) ? "odd" : "even";
})

should return

{
    "odd": [1,3,5],
    "even": [2,4,6]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions