java - Xtend "Movies example" best answer -


I followed extensive tutorials and movies example. At the end of this tutorial, you can find the following question:

  @test def void sumOfVotesOfTop2 () {val long sum = movies.sortBy [ Ratings] .Tak (2) .map [numberofwots]. Royce [a, b | A + B] Asterix (47_22 9L, Yoga)}   

First of all, movies are sorted by rating, then we get the best two. After this, the list of films changes to their list of numberofwaves, which uses the map function. Now we have a list that can be reduced by adding a value to a long one.

You can reduce and reduce instead of map Do you know how?

My question is: What is the best answer for the last question?

I found a way to calculate the same "yoga" value without using the map () extension, but it sounds terrible to me here. Here's my solution:

  assertEquals (47229, this.movies.sortBy [-rating] .take (2) .reduce [m1, m2 | new movie ('', 0, 0.0, m1. NumberOfVotes + m2.numberOfVotes, null]] numberOfVotes   

Is there a better (more cleaner) way to do this? Guna (RB, (R, T ) = & Gt; R function)

Please enter the short ((t, t) => t :
  assertEquals (47229, movies .rtb [rating] .reverseView. That  map ((t) => does not calculate any curious, but evaluated on demand, so perform such performance There should be no difference to the solution which uses the map function. In spite of this,  fold  is quite easy if you have to submit a result for a set of such values Where the result type is different from the element type.   

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -