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.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Functional Programming
  3. Introduction
  4. Filter Positions in a List
  5. Discussions

Filter Positions in a List

Problem
Submissions
Leaderboard
Discussions

Sort 130 Discussions, By:

votes

Please Login in order to post a comment

  • QuomoZ 5 years ago+ 0 comments

    I've been solving these challenges in Haskell without using higher order functions.

    f (_:x:xs) = x : f xs
    f _ = []
    
    52|
    Permalink
  • jeffbarge 6 years ago+ 0 comments

    The default solution input for Scala is broken. I had to delete the entire object Solution { ... and replace it with def f()...

    36|
    Permalink
  • koskinasnapoleon 4 years ago+ 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.

    15|
    Permalink
  • asatna13 4 years ago+ 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?

    14|
    Permalink
  • foru_fy 5 years ago+ 0 comments

    f (x:y:ys) = y: (f ys)
    f _ = []

    10|
    Permalink
Load more conversations

Need Help?


View top submissions
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature