Scheduling is how the processor decides which jobs(processes) get to use the processor and for how long. This can cause a lot of problems. Like a really long process taking the entire CPU and freezing all the other processes. One solution is Shortest Job First(SJF), which today you will be implementing.

SJF works by, well, letting the shortest jobs take the CPU first. If the jobs are the same size then it is First In First Out (FIFO). The idea is that the shorter jobs will finish quicker, so theoretically jobs won't get frozen because of large jobs. (In practice they're frozen because of small jobs).

You will be implementing:
```python
  def SJF(jobs, index)
```

It takes in:

1. "jobs" a non-empty array of positive integers. They represent the clock-cycles(cc) needed to finish the job.
2. "index" a positive integer. That represents the job we're interested in.

SJF returns:

1. A positive integer representing the cc it takes to complete the job at index.

Here's an example:
```
SJF([3, 10, 20, 1, 2], 0)
at 0cc [3, 10, 20, 1, 2] jobs[3] starts
at 1cc [3, 10, 20, 0, 2] jobs[3] finishes, jobs[4] starts
at 3cc [3, 10, 20, 0, 0] jobs[4] finishes, jobs[0] starts
at 6cc [0, 10, 20, 0, 0] jobs[0] finishes
```

so:
```
SJF([3,10,20,1,2], 0) == 6
```

Source: codewars | Difficulty: EASY
Tags: Data structures

Greedy algorithms

Starter code: def SJF(jobs, index):
	

Solutions:
def SJF(jobs, index):
	return sum((j for (i, j) in enumerate(jobs) if j < jobs[index] or (j == jobs[index] and i <= index)))


SJF = lambda jobs, index: sum((j for (i, j) in enumerate(jobs) if j <= jobs[index] and (jobs[i] != jobs[index] or i <= index)))


def SJF(jobs, index):
	return sum((n for (i, n) in enumerate(jobs) if n < jobs[index] + (i <= index)))


def SJF(jobs, index):
	return sum(list(filter(lambda x: x < jobs[index], jobs))) + sum(list(filter(lambda x: x == jobs[index], jobs[0:index + 1])))


def SJF(jobs, index):
	job = jobs[index]
	return sum(sorted(jobs)[:sorted(jobs).index(job) + 1]) + job * jobs[:index].count(job)


SJF = lambda arr, j: sum((k for k in arr if k < arr[j])) + arr[:j + 1].count(arr[j]) * arr[j]


from operator import itemgetter

def SJF(jobs, index):
	total = 0
	for (i, duration) in sorted(enumerate(jobs), key=itemgetter(1)):
		total += duration
		if i == index:
			return total