<commit_before>### Q.1<br>

```scala

def randyArrayOfSize(n:Int) = for(i <- 0 until n; val r = Random) yield r.nextInt
 
```

In Groovy:
```groovy
def randyArrayOfSize = { n -> (0..<n).collect { (new Random()).nextInt() } }
randyArrayOfSize(10)
```

<br>

### Q.2/3<br>

```scala

def swappy(a:Array[Int]) : Seq[Int]= {
  if(a.length % 2 == 0) (for(left <- 0 until (a.length, 2); right <- 1 to (0,-1)) yield a(left+right))
  else swappy(a.init) ++ Array(a.last)
} 

```
In Groovy:
```groovy
def swappy
swappy = { a ->
    if(a.size() % 2 == 0) (0..< a.size()).collect { index -> a[index % 2 == 0 ? index + 1 :index - 1]}
    else swappy(a.init()) + a.last()
}
```
<br>

### Q.4<br>

```scala

def posNeg(aa:Array[Int]) = aa.filter(_ > 0) ++ aa.filter(_ <= 0)

```
In Groovy:
```groovy
def posNeg = { a -> a.grep { it >= 0 } + a.grep { it < 0 } }
```
<br>


### Q.5<br>

```scala

def avg(a:Array[Double]) = if(a.length != 0) a.sum/a.length else 0

```
<br>


### Q.6<br>

```scala

val array = Array(1,2,3,4,5)                      //> array  : Array[Int] = Array(1, 2, 3, 4, 5)<commit_msg>Update chapter3.md<commit_after>### Q.1<br>

```scala

def randyArrayOfSize(n:Int) = for(i <- 0 until n; val r = Random) yield r.nextInt
 
```

In Groovy:
```groovy
def randyArrayOfSize = { n -> (0..<n).collect { (new Random()).nextInt() } }
randyArrayOfSize(10)
```

<br>

### Q.2/3<br>

```scala

def swappy(a:Array[Int]) : Seq[Int]= {
  if(a.length % 2 == 0) (for(left <- 0 until (a.length, 2); right <- 1 to (0,-1)) yield a(left+right))
  else swappy(a.init) ++ Array(a.last)
} 

```
In Groovy:
```groovy
def swappy
swappy = { a ->
    if(a.size() % 2 == 0) (0..< a.size()).collect { index -> a[index % 2 == 0 ? index + 1 :index - 1]}
    else swappy(a.init()) + a.last()
}
```
<br>

### Q.4<br>

```scala

def posNeg(aa:Array[Int]) = aa.filter(_ > 0) ++ aa.filter(_ <= 0)

```
In Groovy:
```groovy
def posNeg = { a -> a.grep { it > 0 } + a.grep { it <= 0 } }
```
<br>


### Q.5<br>

```scala

def avg(a:Array[Double]) = if(a.length != 0) a.sum/a.length else 0

```
<br>


### Q.6<br>

```scala

val array = Array(1,2,3,4,5)                      //> array  : Array[Int] = Array(1, 2, 3, 4, 5)
{'fraction_non_alphanumeric': 0.25468678555098306, 'fraction_numerical': 0.037037037037037035, 'mean_word_length': 2.9566003616636527, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '13416', 'n_tokens_mistral': 1083, 'n_tokens_neox': 963, 'n_words': 228}