Return course order with class prerequisites Question:
Given Input: Courses and their dependencies(prerequisites)
such as A &lt; B; A &lt; C; B &lt; D; C &lt; D return course order in the order a student can take. i.e answer should return A, B, C, D or A, C, B, D

I solved the problem, but the running time is very slow, I cannot seem to figure out how to improve my algorithm. FYI: This isn't for schoolwork or project, just curious.

Answer:

  function getCourseOrder(input) {
  let result = [];

  while(Object.keys(input).length !== 0){
    for (let item in input) {
        let depencies = input[item];

        if (!depencies || depencies.length === 0) {
          delete input[item];
          result.push(item);
          continue;
        }

      let hasAlreadyTakenClasses = depencies.every((currentValue) =&gt; {
        return result.indexOf(currentValue) &gt; -1;
      })

      if (hasAlreadyTakenClasses) {
        delete input[item];
        result.push(item);
      }

    }
  }

  return result;
}

var input =  {a: [], b: ['a'], c: ['a'], d:['c','b'] }
As pointed out in a comment, the problem you are trying to solve is an instance of the more general problem of finding a topological sorting of a particular set.
In your case, the ordering is given by the "being a prerequisite of" relation.
At the implementational level, switching your dictionary with an adjacency matrix may improve the runtime.