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.
Filter Positions in a List
Filter Positions in a List
QuomoZ + 0 comments I've been solving these challenges in Haskell without using higher order functions.
f (_:x:xs) = x : f xs f _ = []
jeffbarge + 0 comments The default solution input for Scala is broken. I had to delete the entire
object Solution { ...
and replace it withdef f()...
koskinasnapoleon + 0 comments In Scala:
def f(arr:List[Int]):List[Int] = arr.zipWithIndex.filter(_._2 %2 == 1).map(_._1)
So, zipWithIndex produces pairs like (28,0) (32,1) (5,2) ...
,where the second element is the index and the first the value in the list. Hold only those pairs for which the index is odd(filter), and return the first element of the pair which is the value(map) by applying the function which just describes holding only the first element of the pair.
asatna13 + 0 comments I ended up with the following haskell solution:
f (x:xs) = (head xs) : f (tail xs)
Obviously, I am a beginner at haskell. Any comments?
foru_fy + 0 comments f (x:y:ys) = y: (f ys)
f _ = []
Load more conversations
Sort 130 Discussions, By:
Please Login in order to post a comment