Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise 26 another way #180

Open
ghost opened this issue Jun 6, 2019 · 0 comments
Open

Exercise 26 another way #180

ghost opened this issue Jun 6, 2019 · 0 comments

Comments

@ghost
Copy link

ghost commented Jun 6, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants