Browse Source

add new picine-discovery exercises

pull/779/head
Clement Denis 3 years ago
parent
commit
8d2a02f417
  1. 30
      js/tests/average.json
  2. 22
      js/tests/count-from-10.json
  3. 30
      js/tests/extremes.json
  4. 22
      js/tests/fikbuk.json
  5. 6
      js/tests/funfunfunction.json
  6. 22
      js/tests/give-back.json
  7. 14
      js/tests/go-to-11.json
  8. 22
      js/tests/olympic.json
  9. 26
      js/tests/power-ranger.json
  10. 30
      js/tests/total.json
  11. 18
      js/tests/ultra-venom-speed-control-system-rgb.json
  12. 18
      js/tests/what-9000.json
  13. 15
      subjects/average/README.md
  14. 15
      subjects/count-from-10/README.md
  15. 3
      subjects/diamon/README.md
  16. 23
      subjects/fikbuk/README.md
  17. 15
      subjects/funfunfunction/README.md
  18. 16
      subjects/give-back/README.md
  19. 20
      subjects/olympic/README.md
  20. 18
      subjects/power-ranger/README.md
  21. 38
      subjects/total/README.md
  22. 14
      subjects/ultra-venom-speed-control-system-rgb/README.md
  23. 9
      subjects/what-9000/README.md

30
js/tests/average.json

@ -0,0 +1,30 @@
[
{
"description": "basic with a single value",
"code": "equal(average([12]), 12)"
},
{
"description": "basic with multiple values",
"code": "equal(average([1, 1, 4]), 2)"
},
{
"description": "Test with negative numbers",
"code": "equal(average([6, 3, -3]), 2)"
},
{
"description": "Test with a bigger array",
"code": "equal(average([1, 4, 8, 12]), 6.25)"
},
{
"description": "Test with 0 values",
"code": "equal(average([]), NaN)"
},
{
"description": "Test with a negative result",
"code": "equal(average([-12, 2, -32]), -14)"
},
{
"description": "Anti Cheesing",
"code": "if (/[1-9]/.test(average)) {\n throw Error('You should not need numbers from 1 to 9')\n}"
}
]

22
js/tests/count-from-10.json

@ -0,0 +1,22 @@
[
{
"description": "Count up to 12",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nfrom10(12)\nequal(\n args.flat().join('\\n'),\n `10\n11\n12`,\n)"
},
{
"description": "Count up to 17",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nfrom10(17)\nequal(\n args.flat().join('\\n'),\n `10\n11\n12\n13\n14\n15\n16\n17`,\n)"
},
{
"description": "Count down to 7",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nfrom10(7)\nequal(\n args.flat().join('\\n'),\n `10\n9\n8\n7`,\n)"
},
{
"description": "Count down to 3",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nfrom10(-3)\nequal(\n args.flat().join('\\n'),\n `10\n9\n8\n7\n6\n5\n4\n3\n2\n1\n0\n-1\n-2\n-3`,\n)"
},
{
"description": "Count to 10",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nfrom10(10)\nequal(args.flat().join('\\n'), '10')"
}
]

30
js/tests/extremes.json

@ -0,0 +1,30 @@
[
{
"description": "Test 1",
"code": "equal(extreme([-1, 0, 10, 5]), { bigest: 10, smallest: -1 })"
},
{
"description": "Test 2",
"code": "equal(extreme([22, 7, 32, 99, 54]), { bigest: 99, smallest: 7 })"
},
{
"description": "Test 3",
"code": "equal(extreme([-5, -22, -7, -32, -99, -54]), { bigest: -5, smallest: -99 })"
},
{
"description": "Test 4",
"code": "equal(extreme([-5, Infinity, -Infinity, -32, -99, -54]), {\n bigest: Infinity,\n smallest: -Infinity,\n})"
},
{
"description": "Test 5",
"code": "equal(extreme([1337]), { bigest: 1337, smallest: 1337 })"
},
{
"description": "Test 6",
"code": "equal(extreme([Infinity]), { bigest: Infinity, smallest: Infinity })"
},
{
"description": "Anti Cheesing",
"code": "if (/[0-9]/.test(extreme)) {\n throw Error('You should not need numbers')\n}"
}
]

22
js/tests/fikbuk.json

@ -0,0 +1,22 @@
[
{
"description": "fikBuk until 3",
"code": "equal(fikBuk(3), [1, 2, 'Fik'])"
},
{
"description": "fikBuk until 5",
"code": "equal(fikBuk(5), [1, 2, 'Fik', 4, 'Buk'])"
},
{
"description": "fikBuk until 20",
"code": "equal(fikBuk(20), [\n 1,\n 2,\n 'Fik',\n 4,\n 'Buk',\n 'Fik',\n 7,\n 8,\n 'Fik',\n 'Buk',\n 11,\n 'Fik',\n 13,\n 14,\n 'FikBuk',\n 16,\n 17,\n 'Fik',\n 19,\n 'Buk',\n])"
},
{
"description": "fikBuk until 10000",
"code": "equal(fikBuk(10000).slice(9990), [\n 9991,\n 9992,\n 'Fik',\n 9994,\n 'Buk',\n 'Fik',\n 9997,\n 9998,\n 'Fik',\n 'Buk',\n])"
},
{
"description": "Anti Cheesing",
"code": "if (/(0|2|4|[6-9])/.test(fikBuk)) {\n throw Error('You should only need numbers 3, 5 and maybe 1')\n}"
}
]

6
js/tests/funfunfunction.json

@ -0,0 +1,6 @@
[
{
"description": "exec execute the given function",
"code": "let count = 0\nexec(() => {})\nexec(() => count++)\nexec(() => {})\nexec(() => count++)\nequal(count, 2)"
}
]

22
js/tests/give-back.json

@ -0,0 +1,22 @@
[
{
"description": "giveBack is declared and is a function",
"code": "equal(typeof giveBack, 'function')"
},
{
"description": "calling giveBack return a function",
"code": "equal(typeof giveBack(), 'function')"
},
{
"description": "giveBack works with numbers",
"code": "equal(giveBack(5)(), 5)"
},
{
"description": "giveBack works with strings",
"code": "equal(giveBack('hello')(), 'hello')"
},
{
"description": "giveBack works with undefined",
"code": "equal(giveBack()(), undefined)"
}
]

14
js/tests/go-to-11.json

@ -0,0 +1,14 @@
[
{
"description": "Count from 0 to 11",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\ngoTo11(0)\n\nequal(\n args.flat().join('\\n'),\n `0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11`,\n)"
},
{
"description": "Count from 0 to 11",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\ngoTo11(10)\n\nequal(\n args.flat().join('\\n'),\n `10\n11`,\n)"
},
{
"description": "Count from 12 to 11 (do nothing)",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\ngoTo11(12)\n\nequal(args.flat().join('\\n'), ``)"
}
]

22
js/tests/olympic.json

@ -0,0 +1,22 @@
[
{
"description": "Should log the gold medal if the Pedro is ranked 1st",
"code": "let athletes = ['Pedro', 'Janine', 'Patrick', 'Bernadette', 'Maria']\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args.flat(), ['πŸ₯‡'])"
},
{
"description": "Should log the silver medal if the Pedro is ranked 2nd",
"code": "let athletes = ['Janine', 'Pedro', 'Patrick', 'Bernadette', 'Maria']\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args.flat(), ['πŸ₯ˆ'])"
},
{
"description": "Should log the bronze medal if the Pedro is ranked 3rd",
"code": "let athletes = ['Maria', 'Janine', 'Pedro', 'Bernadette', 'Patrick']\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args.flat(), ['πŸ₯‰'])"
},
{
"description": "Should log 😞 if Pedro is 4th place or more",
"code": "let athletes = ['Maria', 'Janine', 'Bernadette', 'Patrick', 'Pedro']\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0]?.join(' '), '😞 Pedro is #5')"
},
{
"description": "Should log 😞 if Pedro is 4th place or more",
"code": "let athletes = [\n 'Maria',\n 'Martin',\n 'Janine',\n 'Bernadette',\n 'Jeremy',\n 'Sabrina',\n 'Kilian',\n 'Patrick',\n 'Pedro',\n 'Seb',\n]\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0]?.join(' '), '😞 Pedro is #9')"
}
]

26
js/tests/power-ranger.json

@ -0,0 +1,26 @@
[
{
"description": "from 0 to 5",
"code": "equal(range(0, 5), [0, 1, 2, 3, 4])"
},
{
"description": "from 5 to 0",
"code": "equal(range(5, 0), [5, 4, 3, 2, 1])"
},
{
"description": "from -1 to -3",
"code": "equal(range(-1, -3), [-1, -2])"
},
{
"description": "from 2 to -3",
"code": "equal(range(10, 7), [10, 9, 8])"
},
{
"description": "if the end is equal to the start, return an empty array",
"code": "equal(range(5, 5), [])"
},
{
"description": "Anti Cheesing",
"code": "if (/[2-9]/.test(range)) {\n throw Error('You should not use number from 2 to 9')\n}"
}
]

30
js/tests/total.json

@ -0,0 +1,30 @@
[
{
"description": "basic with a single value",
"code": "equal(total([12]), 12)"
},
{
"description": "basic with multiple values",
"code": "equal(total([1, 1, 3]), 5)"
},
{
"description": "Test with negative numbers",
"code": "equal(total([6, 2, -3]), 5)"
},
{
"description": "Test with a bigger array",
"code": "equal(total([1, 2, 2, 8, 12]), 25)"
},
{
"description": "Test with 0 values",
"code": "equal(total([]), 0)"
},
{
"description": "Test with a negative result",
"code": "equal(total([-12, 2, -32]), -42)"
},
{
"description": "Anti Cheesing",
"code": "if (/[1-9]/.test(total)) {\n throw Error('You should not need numbers from 1 to 9')\n}"
}
]

18
js/tests/ultra-venom-speed-control-system-rgb.json

@ -0,0 +1,18 @@
[
{
"description": "If the temperature is above 90 expect 3200 RPM",
"code": "let temperature = 99\n\n// Your code\n\nequal(fanSpeed, 3200)"
},
{
"description": "If the temperature is above 90 expect 3200 RPM",
"code": "let temperature = 75\n\n// Your code\n\nequal(fanSpeed, 1600)"
},
{
"description": "If the temperature is above 40 expect 800 RPM",
"code": "let temperature = 62\n\n// Your code\n\nequal(fanSpeed, 800)"
},
{
"description": "If the temperature is below 40 expect 0 RPM",
"code": "let temperature = 32\n\n// Your code\n\nequal(fanSpeed, 0)"
}
]

18
js/tests/what-9000.json

@ -0,0 +1,18 @@
[
{
"description": "powerlevel is defined and is a constant number",
"code": "let name = 'Patrick'\n\n// Your code\n\nequal(typeof powerlevel, 'number')"
},
{
"description": "powerlevel is a constant variable and can not be changed",
"code": "let name = 'Patrick'\n\n// Your code\ntry {\n var previousValue = powerlevel\n powerlevel = Math.random()\n} catch (err) {}\n\nequal(powerlevel, previousValue)"
},
{
"description": "Vegeta can not have more than 9000 powerlevel",
"code": "let name = 'Vegeta'\n\n// Your code\n\nequal(powerlevel <= 9000, true)"
},
{
"description": "Goku have more than 9000 powerlevel",
"code": "let name = 'Goku'\n\n// Your code\n\nequal(powerlevel > 9000, true)"
}
]

15
subjects/average/README.md

@ -0,0 +1,15 @@
## Average
### Instructions
Declare the function `average` that compute the average of all the values from
the given array
If the array is empty, `average` should return `NaN`
**Example:**
```js
average([1, 1, 4]) // -> 2
average([1, 4, 8, 12]) // -> 6.25
```

15
subjects/count-from-10/README.md

@ -0,0 +1,15 @@
## Count from 10
### Instructions
Declare `from10` function that takes an `end` number argument.
You must log each number starting at `10` until you reach the `end` value
(included)
If the number is lower than `10` you must count down to it, otherwhise count up
to it.
> Example: `from10(12)` would log: 10 11 12
>
> and `from10(7)` would log: 10 9 8 7

3
subjects/diamon/README.md

@ -0,0 +1,3 @@
## 🌟 Diamon
diamon (pyramid + reversed pyramid)

23
subjects/fikbuk/README.md

@ -0,0 +1,23 @@
## FikBuk
### Instructions
Create a `fikBuk` function that takes a number `n` and will start counting from
`1` to `n`.
You will return create an array from those values
for each numbers in between `1` and `n` you must do the following:
- if the number is a multiple of `3` add `Fik` to the array
- if the number is a multiple of `5` add `Buk` to the array
- if the number is a multiple of both `3` and `5` add `FikBuk` to the array
- otherwise add the number to the array
**Example:**
```js
fikBuk(3) // -> [1, 2, 'Fik']
fikBuk(5) // -> [1, 2, 'Fik', 4, 'Buk']
fikBuk(16) // -> [...7, 8, 'Fik', 'Buk', 11, 'Fik', 13, 14, 'FikBuk', 16]
```

15
subjects/funfunfunction/README.md

@ -0,0 +1,15 @@
## 🌟 FunFunFunction
### Instruction
Declare an `exec` function that takes a function and call it
### Usage
```js
const showMessage = () => {
console.log('Functions inside a function ?!')
}
exec(showMessage) // log 'Functions inside a function ?!'
```

16
subjects/give-back/README.md

@ -0,0 +1,16 @@
## 🌟 Give Back
### Instruction
Declare an `giveBack` function an argument and return a new function that when
called will return the argument of the `giveBack` function
### Usage
```js
const give5 = giveBack(5)
const giveHello = giveBack('Hello')
console.log(give5()) // 5
console.log(giveHello()) // 'Hello'
```

20
subjects/olympic/README.md

@ -0,0 +1,20 @@
## Olympic
### Instructions
The Olympic games just ended and you want to tell everyone about the ranking of
your favorite athlete: Pedro.
For the first to the third position, log the matching medal emoji πŸ₯‡πŸ₯ˆπŸ₯‰.
Otherwhise log this disapointed emoji: 😞 and a message of his exact ranking.
Example, if pedro is in 10th place, the message to log would be:
```js
'😞 Pedro is #10'
```
### Notions
- [indexOf](https://devdocs.io/javascript/global_objects/array/indexof)

18
subjects/power-ranger/README.md

@ -0,0 +1,18 @@
## Power Ranger
### Instructions
Declare the `range` function that takes 2 number arguments: a `start` and an
`end`.
Create an array of numbers starting from the `start` (included) to the `end`
(excluded).
**Example:**
```js
range(0, 5) //-> [0, 1, 2, 3, 4]
range(10, 7) //-> [10, 9, 8]
range(2, -3) //-> [2, 1, 0, -1, -2]
range(-1, -3) //-> [-1, -2]
```

38
subjects/total/README.md

@ -0,0 +1,38 @@
## Total
JS also provide another type of loop than the `while`
### for..of
`for..of` loops are used to iterate _over_ a value, for example you can iterate
over an array:
```js
let heroes = ['Superman', 'Batman', 'Onepuchman', 'Spiderman', 'Ultraman']
// ↙ the for of ↙ keywords
for (let heroe of heroes) {
// <- the value we iterate over
// β†– variable declaration, will be each elements from the value
// in this case, heroes, an array
console.log(heroe)
}
```
From the value we have used so far, only `string` and `array` are iterable.
### Instructions
Declare the function `total` that compute the sum of all the values from the
given array
If the array is empty, `total` should return 0
**Example:**
```js
total([1, 1, 3]) // -> 5
total([6, 2, -3]) // -> 5
total([1, 2, 2]) // -> 5
total([0, -2]) // -> -2
```

14
subjects/ultra-venom-speed-control-system-rgb/README.md

@ -0,0 +1,14 @@
## 🌟 Ultra Venom Speed Control System (RGB)
### Instruction
You are writing the cooling controller of your new gaming PC. \
Declare a constant variable `fanSpeed` of the RPM _(revolutions per minute)_ of your
cooling fan.
Check the provided variable `temperature` to define the `fanSpeed` value:
- If the `temperature` is above `90` define it's value too `3200`
- If the `temperature` is above `70` define it's value too `1600`
- If the `temperature` is above `40` define it's value too `800`
- otherwhise set it's value to `0`

9
subjects/what-9000/README.md

@ -0,0 +1,9 @@
## 🌟 What 9000 ?!
### Instructions
Define the `powerlevel` constant variable from the provided `name` variable to a
number of your choice.
But, only if the name is `'Goku'` the powerlevel must be higher than, of course,
`9000`.
Loading…
Cancel
Save