Skip to content

Exercise 26 another way  #180

Description

I have solve exercise 26 in another way, like this:

lists.map((genre) => {
    return {
        name: genre.name,
        videos: videos.filter((video) => {
            return video.listId == genre.id;
        }).map((filtredVideo) => {
            return {
                id: filtredVideo.id,
                title: filtredVideo.title,
                time: bookmarks.filter((bookmark) => {
                    return bookmark.videoId == filtredVideo.id;
                }).map((filtredBookmark) => {
                    return filtredBookmark.time;
                })[0],
                boxart: boxarts.filter((boxart) => {
                    return boxart.videoId == filtredVideo.id;
                }).reduce((fBoxart1, fBoxart2) => {
                    return fBoxart1.width * fBoxart1.height > fBoxart2.width * fBoxart2.height ? fBoxart2 : fBoxart1;
                }).map((filtredReducedBoxart) => {
                    return filtredReducedBoxart.url;
                })[0]
            };
        })
    };
});

It's a little bit different form original code:

lists.map(function(list) {
    return {
        name: list.name,
        videos:
            videos.
            filter(function(video) {
                return video.listId === list.id;
            }).
            concatMap(function(video) {
                return Array.zip(
                    bookmarks.filter(function(bookmark) {
                        return bookmark.videoId === video.id;
                    }),
                    boxarts.filter(function(boxart) {
                        return boxart.videoId === video.id;
                    }).
                    reduce(function(acc,curr) {
                        return acc.width * acc.height < curr.width * curr.height ? acc : curr;
                    }),
                    function(bookmark, boxart) {
                        return { id: video.id, title: video.title, time: bookmark.time, boxart: boxart.url };
                    });
            })
    };
});

So please tell me... Do my solution is good? If not, why? Maybe it's not "functional thinking"?

And I act like in the first option all time, that how I'm thinking - it's seems simpler for me.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions