title: Sort object by skills
body: <p>So I found a problem in an article (can't find the link or I'd have the solution) that asked the following question. </p>
  
  <p>Given some user data sort users by skill. The following is the data</p>
  
  <pre><code>const namesAndSkills = {
     // Dev : Skills
     mark : ["javascript","react","java"],
     rob : "javascript",
     patrick : ["javascript", "react", "python"]
   } 
  
  Solution(expected output):
  
    Javascript: ["mark", "rob", "patrick"],
    react: ["mark", "patrick"],
    java: mark,
    python: patrick
  </code></pre>
  
  <p>My solution has only been able to separate the skills from the users, but I can't seem to find a way to compare the users with the skills.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const data = {
    // // Dev : Skills
    mark: ["javascript", "react", "java"],
    rob: "javascript",
    patrick: ["javascript", "react", "python"]
  }
  
  function swapNamesAndSkills(object) {
    let data = Object.entries(object); //Was thinking of using the separated entries to compare, but couldn't evaluate correctly.
  
    //Create a map to store our end key / values
    let skillsToNames = new Map();
    let skills = [].concat(...Object.values(object));
    for (let i = 0; i &lt; skills.length; i++) {
      //if map doesnt have the skill as a key, add skill
      if (!skillsToNames.has(skills[i])) {
        //array of names that have the skill
        skillsToNames.set(skills[i], []);
      }
    }
    console.log(skillsToNames);
  }
  swapNamesAndSkills(data);</code></pre>
  </div>
  </div>
  </p>
  
  <p>As you see I was looking at ways forward, but can't seem to land a solid way to reverse the data. Solution doesn't have to solve the problem, I'm just stuck and can't find my way to the finish line.</p>