title: Filter out elements by comparing a list of strings and a map
body: <p>I have two functions which get a list of Strings and a Map as parameters and return a list of Integers. As shown:</p>
  <pre><code>def f1(names: List[String], namemap: Map[String, List[Int]]): List[Int] = 
  
  def f2(names: List[String], namemap: Map[String, List[Int]]): List[Int] =
  </code></pre>
  <p>To make the following explanation more understandable here is an example:</p>
  <pre><code>val nameslist = List(&quot;alex&quot;, &quot;toby&quot;)
  
  val namesmap = Map(&quot;sarah&quot; -&gt; List(5), &quot;toby&quot; -&gt; List(6), &quot;alex&quot; -&gt; List(1, 6))
  
  println(f1(nameslist, namesmap))
  //should print: List(6,1)
  println(f2(nameslist, namesmap))
  //should print: List(6)
  </code></pre>
  <p>The function <code>f1</code> should &quot;compare&quot;? the Strings from the List <code>namelist</code> with the Strings from the Map <code>namesmap</code> and returns all the Integer values from <code>namesmap</code> where the String is found.</p>
  <p>The function <code>f2</code> should only return the Integers which are found in both Strings.</p>