You are viewing a single comment's thread. Return to all comments →
I don't understand why my code doesn't work when there are duplicates in the list
def f ( arr: List[Int] ) : List [Int] = { arr.filter (arr.indexOf ( _ : Int) % 2 != 0) }
f ( List(1,2,3,4,4,5) )
scala List[Int] = List(2, 4, 4, 5) --> this is the result
scala List[Int] = List(2, 4, 4, 5)
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 →
I don't understand why my code doesn't work when there are duplicates in the list
scala List[Int] = List(2, 4, 4, 5)
--> this is the result