user: OK, my warriors! Now that you beat the big BOSS, you can unlock three new skills. (Does it sound like we're playing an RPG? ;-)

## The Arrow Function (JS only)

The first skill is the arrow function. Let's look at some examples to see how it works:

```python
#ignore this part, it is just for JS
```
As you can see, its syntax is:

```python
#ignore this part, it is just for JS
```
If only one parameter exists on the left side of the arrow, the bracket can be omitted. If only one expression exists on the right side of the arrow, the curly braces can also be omitted. The example below shows a function with the () and {} omitted.

```python
#ignore this part, it is just for JS
```
If the right side of the arrow is a complex statement, you must use curly braces:

```python
#ignore this part, it is just for JS
```
So far, our examples have used function assignment. However, an arrow function can also be used as a parameter to a function call, as well. When used as a parameter, the arrow function does not require a name. Let's rewrite the string.replace() example we saw from a previous training using our new skill:

```python
#ignore this part, it is just for JS
```
String.replace takes a regular expression and a function. The function is invoked on each substring matching the regex, and return the string replacement of that match. In this case, the arrow function takes the matched string as the parameter ```x```, and returns the upper cased value of ```x```.

In the soon to learn the arrayObject and its methods, there are many applications on the arrow function, which is the reason we first learn the arrow function. The arrow function has more complex usage and usage restrictions, but we don't need to learn to be so deep, so we only learn the contents of the above.

## The Spread Operator

The second skill is the ```spread operator```. The spread operator allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) are expected.

It looks like this: ...obj. It can be used in three places:

1\. In function calls:

```python
def plus(a,b,c,d,e): return a+b+c+d+e

arg1=[1,2,3,4,5]
arg2=[2,3]
print plus(...arg1) #output is 15
print plus(...arg2) #output is 5
```
```...arg1``` spreads all the elements in arg1 into individual parameters to plus(). 
In Javascript, it's also possible to use the spread operator in the middle of a parameter list, as was done with ```...arg2```.

2\. Creating array literals (JS and Ruby):
```python
#ignore this part, it is just for JS and Ruby
```
```...a``` spreads out the array's elements, making them individual elements in b.

3\. Used for ```deconstruction```. destructuring is also a new member of ES6. It is the third skill we learn in this training.

First, let's look at a simple example of destructuring:
```python
a,b=[1,2] #or [a,b]=[1,2]
print a #output is 1
print b #output is 2
```
Destructuring allows us to assign variables in a sentence-like form. Here's a slightly more complicated example:
```python
a,b=[1,2] #or [a,b]=[1,2]
#old way to swap them:
#c=a; a=b; c=b
b,a=[a,b] #or [b,a]=[a,b]
print a #output is 2
print b #output is 1
```
With destructuring, we don't need a temporary variable to help us exchange the two values.

You can use the spread operator for destructuring like this:

```python
#ignore this part, it is just for JS
```
Please note: the spread operator must  be the last variable: ```[...a,b]=[1,2,3,4,5]``` does not work.

```a``` was assigned to the first element of the array, and``` b ```was initialized with the remaining elements in the array.

Javascript note: If you see an ellipse ... in the argument list in a function declaration, it is not a spread operator, it is a structure called rest parameters. The rest parameter syntax allows us to represent an indefinite number of arguments as an array, like this:

```python
def plus(*num):
  rs=0
  for x in num: rs+=x
  return rs
print plus(1,2) #output is 3
print plus(3,4,5) #output is 12
```
The rest paramater must be the last argument in the function definition argument list.

In the next example, we use a rest parameter to collect all the values passed to mul() after the first into an array. We then multiply each of them by the first parameter and return that array:
```python
def mul(a,*b):
  b=list(b) #default type would be tuple
  for i in xrange(len(b)): b[i]*=a
  return b
print mul(2,1,1,1) #output is [2,2,2]
print mul(2,1,2,3,4) #output is [2,4,6,8]
```

Ok, the lesson is over. Did you get it all? Let's do a task, now.

## Task

Create a function ```shuffleIt```. The function accepts two or more parameters. The first parameter arr is an array of numbers, followed by an arbitrary number of numeric arrays. Each numeric array contains two numbers, which are indices for elements in arr (the numbers will always be within bounds). For every such array, swap the elements. Try to use all your new skills: arrow functions, the spread operator, destructuring, and rest parameters.

Example:
```
shuffleIt([1,2,3,4,5],[1,2]) should return [1,3,2,4,5]
shuffleIt([1,2,3,4,5],[1,2],[3,4]) should return [1,3,2,5,4]
shuffleIt([1,2,3,4,5],[1,2],[3,4],[2,3]) should return [1,3,5,2,4]
```

[Next training (#23 Array Methods) >>](http://www.codewars.com/kata/572af273a3af3836660014a1)
    
## [Series](http://github.com/myjinxin2015/Katas-list-of-Training-JS-series)

( ↑↑↑ Click the link above can get my newest kata list, Please add it to your favorites)

 - [#1: create your first JS function helloWorld](http://www.codewars.com/kata/571ec274b1c8d4a61c0000c8)
 - [#2: Basic data types--Number](http://www.codewars.com/kata/571edd157e8954bab500032d)
 - [#3:  Basic data types--String](http://www.codewars.com/kata/571edea4b625edcb51000d8e)
 - [#4:  Basic data types--Array](http://www.codewars.com/kata/571effabb625ed9b0600107a)
 - [#5:  Basic data types--Object](http://www.codewars.com/kata/571f1eb77e8954a812000837)
 - [#6:  Basic data types--Boolean and conditional statements if..else](http://www.codewars.com/kata/571f832f07363d295d001ba8)
 - [#7:  if..else and ternary operator](http://www.codewars.com/kata/57202aefe8d6c514300001fd)
 - [#8: Conditional statement--switch](http://www.codewars.com/kata/572059afc2f4612825000d8a)
 - [#9: loop statement --while and do..while](http://www.codewars.com/kata/57216d4bcdd71175d6000560)
 - [#10: loop statement --for](http://www.codewars.com/kata/5721a78c283129e416000999)
 - [#11: loop statement --break,continue](http://www.codewars.com/kata/5721c189cdd71194c1000b9b)
 - [#12: loop statement --for..in and for..of](http://www.codewars.com/kata/5722b3f0bd5583cf44001000)
 - [#13: Number object and  its properties](http://www.codewars.com/kata/5722fd3ab7162a3a4500031f)
 - [#14: Methods of Number object--toString() and toLocaleString()](http://www.codewars.com/kata/57238ceaef9008adc7000603)
 - [#15: Methods of Number object--toFixed(), toExponential() and toPrecision()](http://www.codewars.com/kata/57256064856584bc47000611)
 - [#16: Methods of String object--slice(), substring() and substr()](http://www.codewars.com/kata/57274562c8dcebe77e001012)
 - [#17: Methods of String object--indexOf(), lastIndexOf() and search()](http://www.codewars.com/kata/57277a31e5e51450a4000010)
 - [#18: Methods of String object--concat() split() and its good friend join()](http://www.codewars.com/kata/57280481e8118511f7000ffa)
 - [#19: Methods of String object--toUpperCase() toLowerCase() and replace()](http://www.codewars.com/kata/5728203b7fc662a4c4000ef3)
 - [#20: Methods of String object--charAt() charCodeAt() and fromCharCode()](http://www.codewars.com/kata/57284d23e81185ae6200162a)
 - [#21: Methods of String object--trim() and the string template](http://www.codewars.com/kata/5729b103dd8bac11a900119e)
 - [#22: Unlock new skills--Arrow function,spread operator and deconstruction](http://www.codewars.com/kata/572ab0cfa3af384df7000ff8)
 - [#23: methods of arrayObject---push(), pop(), shift() and unshift()](http://www.codewars.com/kata/572af273a3af3836660014a1)
 - [#24: methods of arrayObject---splice() and slice()](http://www.codewars.com/kata/572cb264362806af46000793)
 - [#25: methods of arrayObject---reverse() and sort()](http://www.codewars.com/kata/572df796914b5ba27c000c90)
 - [#26: methods of arrayObject---map()](http://www.codewars.com/kata/572fdeb4380bb703fc00002c)
 - [#27: methods of arrayObject---filter()](http://www.codewars.com/kata/573023c81add650b84000429)
 - [#28: methods of arrayObject---every() and some()](http://www.codewars.com/kata/57308546bd9f0987c2000d07)
 - [#29: methods of arrayObject---concat() and join()](http://www.codewars.com/kata/5731861d05d14d6f50000626)
 - [#30: methods of arrayObject---reduce() and reduceRight()](http://www.codewars.com/kata/573156709a231dcec9000ee8)
 - [#31: methods of arrayObject---isArray() indexOf() and toString()](http://www.codewars.com/kata/5732b0351eb838d03300101d)
 - [#32: methods of Math---round() ceil() and floor()](http://www.codewars.com/kata/5732d3c9791aafb0e4001236)
 - [#33: methods of Math---max() min() and abs()](http://www.codewars.com/kata/5733d6c2d780e20173000baa)
 - [#34: methods of Math---pow() sqrt() and cbrt()](http://www.codewars.com/kata/5733f948d780e27df6000e33)
 - [#35: methods of Math---log() and its family](http://www.codewars.com/kata/57353de879ccaeb9f8000564)
 - [#36: methods of Math---kata author's lover:random()](http://www.codewars.com/kata/5735956413c2054a680009ec)
 - [#37: Unlock new weapon---RegExp Object](http://www.codewars.com/kata/5735e39313c205fe39001173)
 - [#38: Regular Expression--"^","$", "." and test()](http://www.codewars.com/kata/573975d3ac3eec695b0013e0)
 - [#39: Regular Expression--"?", "*", "+" and "{}"](http://www.codewars.com/kata/573bca07dffc1aa693000139)
 - [#40: Regular Expression--"|", "[]" and "()"](http://www.codewars.com/kata/573d11c48b97c0ad970002d4)
 - [#41: Regular Expression--"\"](http://www.codewars.com/kata/573e6831e3201f6a9b000971)
 - [#42: Regular Expression--(?:), (?=) and (?!)](http://www.codewars.com/kata/573fb9223f9793e485000453)

Answer: {"fn_name": "shuffle_it", "inputs": [[[1, 2, 3, 4, 5], [1, 2]], [[1, 2, 3, 4, 5], [1, 2], [3, 4]], [[1, 2, 3, 4, 5], [1, 2], [3, 4], [2, 3]], [[1, 2, 3, 4, 5], [4, 4]], [[1, 2, 3, 4, 5]]], "outputs": [[[1, 3, 2, 4, 5]], [[1, 3, 2, 5, 4]], [[1, 3, 5, 2, 4]], [[1, 2, 3, 4, 5]], [[1, 2, 3, 4, 5]]]}