## Emotional Sort ( ︶︿︶)

You'll have a function called "**sortEmotions**" that will return an array of **emotions** sorted. It has two parameters, the first parameter called "**arr**" will expect an array of **emotions** where an **emotion** will be one of the following:

- **:D** -> Super Happy
- **:)** -> Happy
- **:|** -> Normal
- **:(** -> Sad
- **T\_T** -> Super Sad

Example of the array:``[ 'T_T', ':D', ':|', ':)', ':(' ]``

And the second parameter is called "**order**", if this parameter is **true** then the order of the emotions will be descending (from **Super Happy** to **Super Sad**) if it's **false** then it will be ascending (from **Super Sad** to **Super Happy**)

Example if **order** is true with the above array: ``[ ':D', ':)', ':|', ':(', 'T_T' ]``

- Super Happy -> Happy -> Normal -> Sad -> Super Sad

If **order** is false: ``[ 'T_T', ':(', ':|', ':)', ':D' ]``

- Super Sad -> Sad -> Normal -> Happy -> Super Happy

Example:
```
arr = [':D', ':|', ':)', ':(', ':D']
sortEmotions(arr, true) // [ ':D', ':D', ':)', ':|', ':(' ]
sortEmotions(arr, false) // [ ':(', ':|', ':)', ':D', ':D' ]

```

**More in test cases!**

Notes:
- The array could be empty, in that case return the same empty array ¯\\\_( ツ )\_/¯
- All **emotions** will be valid

## Enjoy! (づ｡◕‿‿◕｡)づ

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Sorting

Data structures

Starter code: def sort_emotions(arr, order):
	

Solutions:
def sort_emotions(arr, order):
	return sorted(arr, key=[':D', ':)', ':|', ':(', 'T_T'].index, reverse=not order)


def get_face(face):
	faces = {':D': 0, ':)': 1, ':|': 2, ':(': 3, 'T_T': 4}
	return faces[face]

def sort_emotions(arr, order):
	return sorted(arr, key=get_face, reverse=not order)


def sort_emotions(arr, reverse, ordered_emotions={smiley: idx for (idx, smiley) in enumerate('T_T :( :| :) :D'.split())}):
	return sorted(arr, reverse=reverse, key=ordered_emotions.get)


sort_emotions = lambda a, b: sorted(a, key=':(:|:):D'.find, reverse=b)


def sort_emotions(arr, order):
	return sorted(arr, key=lambda x: ['T_T', ':(', ':|', ':)', ':D'].index(x), reverse=order)


val = {':D': 4, ':)': 3, ':|': 2, ':(': 1, 'T_T': 0}.__getitem__

def sort_emotions(arr, order):
	return sorted(arr, reverse=order, key=val)


emotions = {'T_T': 1, ':(': 2, ':|': 3, ':)': 4, ':D': 5}

def sort_emotions(lst, desc):
	return sorted(lst, key=emotions.get, reverse=desc)


rank = {x: i for (i, x) in enumerate([':D', ':)', ':|', ':(', 'T_T'])}

def sort_emotions(arr, order):
	return sorted(arr, key=rank.get, reverse=not order)


def sort_emotions(arr, order):
	order_dict = {':D': 1, ':)': 2, ':|': 3, ':(': 4, 'T_T': 5}
	return sorted(arr, key=lambda x: order_dict[x], reverse=not order)


ORDER = {v: i for (i, v) in enumerate([':D', ':)', ':|', ':(', 'T_T'])}

def sort_emotions(arr, order):
	return sorted(arr, key=ORDER.__getitem__, reverse=not order)