Greedy Dwarf Javascript sol