We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The _ at the start is just a quick way to express the argument in the function you're making.
_._2%2!=0
could be done like so:
tp=>tp._2%2!=0
Now, we are working with tuples here, that's what zipWithIndex gives you. The values themselves, each paired up with their index.
So, _ in this case is a tuple (read up on them, they're basically batched variables like I described above), which is why I use the accessors _1 and _2 to refer to its first and second elements (that's just a Scala thing). For this, the second element is the index and the first its associated value in arr.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Filter Positions in a List
You are viewing a single comment's thread. Return to all comments →
The _ at the start is just a quick way to express the argument in the function you're making.
could be done like so:
Now, we are working with tuples here, that's what zipWithIndex gives you. The values themselves, each paired up with their index. So, _ in this case is a tuple (read up on them, they're basically batched variables like I described above), which is why I use the accessors _1 and _2 to refer to its first and second elements (that's just a Scala thing). For this, the second element is the index and the first its associated value in
arr
.