Browse Source

discovery-js: add more exercises

pull/788/head
Clement Denis 3 years ago
parent
commit
d3a8b56646
  1. 18
      js/tests/about-time.json
  2. 14
      js/tests/give-me-the-code.json
  3. 8
      js/tests/half-a-million.json
  4. 18
      js/tests/jaden-case.json
  5. 14
      js/tests/names-plz.json
  6. 14
      js/tests/no-adults-wanted.json
  7. 18
      js/tests/speed-run.json
  8. 10
      js/tests/squared.json
  9. 4
      js/tests/two-can-play-that-game.json
  10. 6
      subjects/3-directions/README.md
  11. 2
      subjects/a-winning-argument/README.md
  12. 38
      subjects/about-time/README.md
  13. 11
      subjects/access/README.md
  14. 21
      subjects/give-me-the-code/README.md
  15. 15
      subjects/half-a-million/README.md
  16. 17
      subjects/jaden-case/README.md
  17. 8
      subjects/keep/README.md
  18. 4
      subjects/level-up/README.md
  19. 43
      subjects/names-plz/README.md
  20. 44
      subjects/no-adults-wanted/README.md
  21. 3
      subjects/recursion/README.md
  22. 34
      subjects/speed-run/README.md
  23. 48
      subjects/squared/README.md
  24. 4
      subjects/swapy/README.md

18
js/tests/about-time.json

@ -0,0 +1,18 @@
[
{
"description": "Test TOP 2",
"code": "equal(\n ultimateScoreboard(\n [\n { duration: 122, name: 'Muntaser' },\n { duration: 235, name: 'Noura' },\n { duration: 927, name: 'Maitha' },\n ],\n 2,\n ),\n ['#01 - 02:02, Muntaser', '#02 - 03:55, Noura'],\n)"
},
{
"description": "Test TOP 5",
"code": "equal(\n ultimateScoreboard(\n [\n { duration: 60, name: 'Wasan' },\n { duration: 237, name: 'Ibrahim' },\n { duration: 302, name: 'Alanoud' },\n { duration: 411, name: 'Hessa' },\n { duration: 499, name: 'Mariam' },\n { duration: 514, name: 'Meriem' },\n { duration: 524, name: 'Sarah' },\n { duration: 567, name: 'Mehnaz' },\n { duration: 891, name: 'maitha' },\n { duration: 967, name: 'Shadha' },\n { duration: 982, name: 'Hala' },\n { duration: 1124, name: 'Lina' },\n { duration: 1137, name: 'Alanoud' },\n { duration: 1138, name: 'Asmaa' },\n { duration: 1170, name: 'Abdulkarim' },\n ],\n 5,\n ),\n [\n '#01 - 01:00, Wasan',\n '#02 - 03:57, Ibrahim',\n '#03 - 05:02, Alanoud',\n '#04 - 06:51, Hessa',\n '#05 - 08:19, Mariam',\n ],\n)"
},
{
"description": "Test top 10",
"code": "equal(\n ultimateScoreboard(\n [\n { duration: 101, name: 'Clement' },\n { duration: 120, name: 'Yahya' },\n { duration: 158, name: 'Rahimul' },\n { duration: 354, name: 'Muntaser' },\n { duration: 374, name: 'Marie' },\n { duration: 427, name: 'Jawaher' },\n { duration: 621, name: 'Hamda' },\n { duration: 841, name: 'Haya' },\n { duration: 860, name: 'Aaesha' },\n { duration: 1012, name: 'Karim' },\n { duration: 1041, name: 'Noor' },\n { duration: 1071, name: 'AM' },\n { duration: 1112, name: 'Mahraalk' },\n { duration: 1124, name: 'Ali' },\n { duration: 3797, name: 'Fady' },\n ],\n 10,\n ),\n [\n '#01 - 01:41, Clement',\n '#02 - 02:00, Yahya',\n '#03 - 02:38, Rahimul',\n '#04 - 05:54, Muntaser',\n '#05 - 06:14, Marie',\n '#06 - 07:07, Jawaher',\n '#07 - 10:21, Hamda',\n '#08 - 14:01, Haya',\n '#09 - 14:20, Aaesha',\n '#10 - 16:52, Karim',\n ],\n)"
},
{
"description": "Test TOP 20",
"code": "equal(\n ultimateScoreboard(\n [\n { duration: 17, name: 'Masood' },\n { duration: 48, name: 'Mehnaz' },\n { duration: 95, name: 'Hessa' },\n { duration: 96, name: 'Fareaa' },\n { duration: 97, name: 'Mariam' },\n { duration: 133, name: 'shamma' },\n { duration: 143, name: 'Laila' },\n { duration: 144, name: 'Reem' },\n { duration: 222, name: 'aisha' },\n { duration: 242, name: 'Maitha' },\n { duration: 249, name: 'noura' },\n { duration: 427, name: 'Hello' },\n { duration: 452, name: 'Zahra' },\n { duration: 470, name: 'Aisha' },\n { duration: 594, name: 'Wasan' },\n { duration: 703, name: 'shaikha' },\n { duration: 716, name: 'Maitha' },\n { duration: 762, name: 'mariam' },\n { duration: 770, name: 'Tanzeel' },\n { duration: 796, name: 'Mohammed' },\n { duration: 803, name: 'Mibin' },\n { duration: 885, name: 'salma' },\n { duration: 899, name: 'Mai' },\n { duration: 905, name: 'khadija' },\n { duration: 1032, name: 'Fatima' },\n { duration: 1093, name: 'Salama' },\n { duration: 1194, name: 'Samira' },\n ],\n 20,\n ),\n [\n '#01 - 00:17, Masood',\n '#02 - 00:48, Mehnaz',\n '#03 - 01:35, Hessa',\n '#04 - 01:36, Fareaa',\n '#05 - 01:37, Mariam',\n '#06 - 02:13, shamma',\n '#07 - 02:23, Laila',\n '#08 - 02:24, Reem',\n '#09 - 03:42, aisha',\n '#10 - 04:02, Maitha',\n '#11 - 04:09, noura',\n '#12 - 07:07, Hello',\n '#13 - 07:32, Zahra',\n '#14 - 07:50, Aisha',\n '#15 - 09:54, Wasan',\n '#16 - 11:43, shaikha',\n '#17 - 11:56, Maitha',\n '#18 - 12:42, mariam',\n '#19 - 12:50, Tanzeel',\n '#20 - 13:16, Mohammed',\n ],\n)"
}
]

14
js/tests/give-me-the-code.json

@ -0,0 +1,14 @@
[
{
"description": "Test with the example data",
"code": "equal(\n jsFileOnly([\n 'essay.docx',\n 'index.html',\n 'info.txt',\n 'lib.js',\n 'README.md',\n 'script.js',\n ]),\n ['lib.js', 'script.js'],\n)"
},
{
"description": "Test with more data",
"code": "equal(\n jsFileOnly([\n '2021-05-03 10-20-34.mkv',\n 'app.js',\n 'app.min.js',\n 'com.debug',\n 'Component.jsx',\n 'config.yml',\n 'package.json',\n 'Pictures',\n 'service.log',\n ]),\n ['app.js', 'app.min.js'],\n)"
},
{
"description": "Test with a larger dataset",
"code": "equal(\n jsFileOnly([\n 'LICENSE',\n 'README.md',\n 'api',\n 'api/auth.js',\n 'api/db.js',\n 'api/defs.js',\n 'api/router.js',\n 'api/server.js',\n 'app.jsx',\n 'component',\n 'component/elements.jsx',\n 'component/form.jsx',\n 'component/header.jsx',\n 'component/icons.jsx',\n 'data',\n 'data/ascii.js',\n 'data/discord.js',\n 'dev',\n 'dev/build.js',\n 'dev/ci.js',\n 'dev/deploy.js',\n 'dev/janus-discord.js',\n 'dev/janus-kv.js',\n 'dev/janus.js',\n 'dev/mocks.js',\n 'dev/request-runner.js',\n 'dev/server.js',\n 'dev/test-runner.js',\n 'dev/test_api_auth.js',\n 'dev/test_lib_eve.js',\n 'dev/test_lib_router.js',\n 'dev/utils.js',\n 'lib',\n 'lib/auth.js',\n 'lib/dom.js',\n 'lib/env.js',\n 'lib/eve.js',\n 'lib/hooks.js',\n 'lib/preact-shim-dev.js',\n 'lib/preact-shim.js',\n 'lib/router.js',\n 'lib/state.js',\n 'package-lock.json',\n 'package.json',\n 'page',\n 'page/home.jsx',\n 'page/profile.jsx',\n 'script',\n 'script/build.sh',\n 'script/deploy.sh',\n 'script/start.sh',\n 'script/test.sh',\n 'template',\n 'template/index.html',\n 'wrangler.toml',\n ]),\n [\n 'api/auth.js',\n 'api/db.js',\n 'api/defs.js',\n 'api/router.js',\n 'api/server.js',\n 'data/ascii.js',\n 'data/discord.js',\n 'dev/build.js',\n 'dev/ci.js',\n 'dev/deploy.js',\n 'dev/janus-discord.js',\n 'dev/janus-kv.js',\n 'dev/janus.js',\n 'dev/mocks.js',\n 'dev/request-runner.js',\n 'dev/server.js',\n 'dev/test-runner.js',\n 'dev/test_api_auth.js',\n 'dev/test_lib_eve.js',\n 'dev/test_lib_router.js',\n 'dev/utils.js',\n 'lib/auth.js',\n 'lib/dom.js',\n 'lib/env.js',\n 'lib/eve.js',\n 'lib/hooks.js',\n 'lib/preact-shim-dev.js',\n 'lib/preact-shim.js',\n 'lib/router.js',\n 'lib/state.js',\n ],\n)"
}
]

8
js/tests/half-a-million.json

@ -1,14 +1,14 @@
[
{
"description": "You must retrieve '1/2 MM $' from the vault using the secret",
"code": "let secret = '53CR37-k0D3'\nlet vault = { '53CR37-k0D3': '1/2 MM $' }\n// Your code\nequal(loot, '1/2 MM $')"
"code": "let secret = '53CR37-k0D3'\nconst vault = { '53CR37-k0D3': '1/2 MM $' }\n\n// Your code\n\nequal(loot, '1/2 MM $')"
},
{
"description": "You must retrieve 500000 from the vault using the secret",
"code": "let secret = '53(.-3T /<o|)3'\nlet vault = { '53(.-3T /<o|)3': 500000 }\n// Your code\nequal(loot, 500000)"
"code": "let secret = '53(.-3T /<o|)3'\nconst vault = { '53(.-3T /<o|)3': 500000 }\n\n// Your code\n\nequal(loot, 500000)"
},
{
"description": "You must change the value of the vault",
"code": "let secret = '53CR37-k0D3'\nlet vault = { '53CR37-k0D3': '1/2 MM $' }\n// Your code\nif (vault['53CR37-k0D3'] === '1/2 MM $') {\n throw Error('vault value was not changed')\n}"
"description": "You must change the value of the vault secret",
"code": "let secret = '53CR37-k0D3'\nconst vault = { '53CR37-k0D3': '1/2 MM $' }\n\n// Your code\n\nequal(typeof vault['53CR37-k0D3'], 'string')\n\nif (vault['53CR37-k0D3'] === '1/2 MM $') {\n throw Error('vault value was not changed')\n}"
}
]

18
js/tests/jaden-case.json

@ -0,0 +1,18 @@
[
{
"description": "Test 1",
"code": "equal(toJadenCase('there is no dress'), 'There Is No Dress')"
},
{
"description": "Test 2",
"code": "equal(\n toJadenCase(\"skinny legend. Don't drink soda\"),\n \"Skinny Legend. Don't Drink Soda\",\n)"
},
{
"description": "Test 3",
"code": "equal(\n toJadenCase(\"how can mirrors be real if our eyes aren't real\"),\n \"How Can Mirrors Be Real If Our Eyes Aren't Real\",\n)"
},
{
"description": "Test 4",
"code": "equal(\n toJadenCase(\n \"BIG MOOD. if I had a nickel for every time I've cried in the back of an UBER, I would have another pair of yeezy's.\",\n ),\n \"Big Mood. If I Had A Nickel For Every Time I've Cried In The Back Of An Uber, I Would Have Another Pair Of Yeezy's.\",\n)"
}
]

14
js/tests/names-plz.json

@ -0,0 +1,14 @@
[
{
"description": "Tests with some names",
"code": "equal(\n namePlz([\n { name: 'Aisha' },\n { name: 'Zahra' },\n { name: 'Hessa' },\n { name: 'Noura' },\n { name: 'Abdulkarim' },\n { name: 'Muntaser' },\n { name: 'Mehnaz' },\n ]),\n 'Aisha, Zahra, Hessa, Noura, Abdulkarim, Muntaser, Mehnaz',\n)"
},
{
"description": "Tests with names of the example",
"code": "equal(\n namePlz([\n { name: 'Wasan' },\n { name: 'Alanoud' },\n { name: 'Salama' },\n { name: 'Yousuf' },\n { name: 'Maitha' },\n ]),\n 'Wasan, Alanoud, Salama, Yousuf, Maitha',\n)"
},
{
"description": "Tests with an empty array",
"code": "equal(namePlz([]), '')"
}
]

14
js/tests/no-adults-wanted.json

@ -0,0 +1,14 @@
[
{
"description": "If no values are lower than 18 we should get exactly the same result",
"code": "equal(childrenOnly([1, 2, 3]), [1, 2, 3])"
},
{
"description": "If some values are over or equal to 18 we should not have them in the result",
"code": "equal(childrenOnly([20, 1, 18, 2, 99, 18, 3]), [1, 2, 3])"
},
{
"description": "Confirm that it works with more values",
"code": "equal(childrenOnly([17, 20, 1, 18, 2, 99, 18, 3, 54, 43, 14, 24, 13]), [\n 17,\n 1,\n 2,\n 3,\n 14,\n 13,\n])"
}
]

18
js/tests/speed-run.json

@ -0,0 +1,18 @@
[
{
"description": "Test 1",
"code": "equal(\n scoreboard([\n { name: 'Noura', duration: 235 },\n { name: 'Maitha', duration: 927 },\n { name: 'Muntaser', duration: 122 },\n ]),\n ['Noura, 235 seconds', 'Muntaser, 122 seconds'],\n)"
},
{
"description": "Test 2",
"code": "equal(\n scoreboard([\n { name: 'Ibrahim', duration: 237 },\n { name: 'Mehnaz', duration: 567 },\n { name: 'Alanoud', duration: 302 },\n { name: 'Asmaa', duration: 1138 },\n { name: 'maitha', duration: 891 },\n { name: 'Shadha', duration: 967 },\n { name: 'Sarah', duration: 524 },\n { name: 'Mariam', duration: 499 },\n { name: 'Alanoud', duration: 1137 },\n { name: 'Abdulkarim', duration: 1170 },\n { name: 'Hessa', duration: 411 },\n { name: 'Hala', duration: 982 },\n { name: 'Wasan', duration: 60 },\n { name: 'Lina', duration: 1124 },\n { name: 'Meriem', duration: 514 },\n ]),\n [\n 'Ibrahim, 237 seconds',\n 'Mehnaz, 567 seconds',\n 'Alanoud, 302 seconds',\n 'Sarah, 524 seconds',\n 'Mariam, 499 seconds',\n 'Hessa, 411 seconds',\n 'Wasan, 60 seconds',\n 'Meriem, 514 seconds',\n ],\n)"
},
{
"description": "Test 3",
"code": "equal(\n scoreboard([\n { name: 'Clement', duration: 101 },\n { name: 'Fady', duration: 3797 },\n { name: 'Karim', duration: 1012 },\n { name: 'Marie', duration: 374 },\n { name: 'Yahya', duration: 120 },\n { name: 'Jawaher', duration: 427 },\n { name: 'Noor', duration: 1041 },\n { name: 'Aaesha', duration: 860 },\n { name: 'Haya', duration: 841 },\n { name: 'Mahraalk', duration: 1112 },\n { name: 'Hamda', duration: 621 },\n { name: 'Rahimul', duration: 158 },\n { name: 'Muntaser', duration: 354 },\n { name: 'AM', duration: 1071 },\n { name: 'Ali', duration: 1124 },\n ]),\n [\n 'Clement, 101 seconds',\n 'Marie, 374 seconds',\n 'Yahya, 120 seconds',\n 'Jawaher, 427 seconds',\n 'Hamda, 621 seconds',\n 'Rahimul, 158 seconds',\n 'Muntaser, 354 seconds',\n ],\n)"
},
{
"description": "Test 4",
"code": "equal(\n scoreboard([\n { name: 'Fareaa', duration: 96 },\n { name: 'Maitha', duration: 716 },\n { name: 'aisha', duration: 222 },\n { name: 'mariam', duration: 762 },\n { name: 'Hessa', duration: 95 },\n { name: 'shamma', duration: 133 },\n { name: 'khadija', duration: 905 },\n { name: 'Laila', duration: 143 },\n { name: 'salma', duration: 885 },\n { name: 'noura', duration: 249 },\n { name: 'Mehnaz', duration: 48 },\n { name: 'Mai', duration: 899 },\n { name: 'Samira', duration: 1194 },\n { name: 'Mibin', duration: 803 },\n { name: 'Masood', duration: 17 },\n { name: 'Salama', duration: 1093 },\n { name: 'Mohammed', duration: 796 },\n { name: 'Zahra', duration: 452 },\n { name: 'Aisha', duration: 470 },\n { name: 'Fatima', duration: 1032 },\n { name: 'Tanzeel', duration: 770 },\n { name: 'Wasan', duration: 594 },\n { name: 'shaikha', duration: 703 },\n { name: 'Mariam', duration: 97 },\n { name: 'Hello', duration: 427 },\n { name: 'Maitha', duration: 242 },\n { name: 'Reem', duration: 144 },\n ]),\n [\n 'Fareaa, 96 seconds',\n 'Maitha, 716 seconds',\n 'aisha, 222 seconds',\n 'Hessa, 95 seconds',\n 'shamma, 133 seconds',\n 'Laila, 143 seconds',\n 'noura, 249 seconds',\n 'Mehnaz, 48 seconds',\n 'Masood, 17 seconds',\n 'Zahra, 452 seconds',\n 'Aisha, 470 seconds',\n 'Wasan, 594 seconds',\n 'shaikha, 703 seconds',\n 'Mariam, 97 seconds',\n 'Hello, 427 seconds',\n 'Maitha, 242 seconds',\n 'Reem, 144 seconds',\n ],\n)"
}
]

10
js/tests/squared.json

@ -0,0 +1,10 @@
[
{
"description": "Test 1",
"code": "equal(toSquares([1, 2, 3, 4]), [1, 4, 9, 16])"
},
{
"description": "Test 2",
"code": "equal(toSquares([10, 22, 3, 5, 16]), [100, 484, 9, 25, 256])"
}
]

4
js/tests/two-can-play-that-game.json

@ -9,7 +9,7 @@
},
{
"description": "duos logs the expected result",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nduos('Batman', 'Robin')\nduos('Pinky', 'The Brain')\nduos('Bonnie', 'Clyde')\nduos('Mr.', 'Mrs.Smith')\n\nequal(\n args.map(arg => arg.join(' ')),\n [\n 'Batman and Robin !',\n 'Pinky and The Brain !',\n 'Bonnie and Clyde !',\n 'Mr. and Mrs.Smith !',\n ],\n)"
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nduos('Batman', 'Robin')\nduos('Pinky', 'The Brain')\nduos('Bonnie', 'Clyde')\nduos('Mr.', 'Mrs.Smith')\n\nequal(\n args.map((arg) => arg.join(' ')),\n [\n 'Batman and Robin !',\n 'Pinky and The Brain !',\n 'Bonnie and Clyde !',\n 'Mr. and Mrs.Smith !',\n ],\n)"
},
{
"description": "duosWork is defined and is a function",
@ -21,6 +21,6 @@
},
{
"description": "duosWork logs the expected result",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nduosWork('Batman', 'Robin', 'protect Gotham')\nduosWork('Pinky', 'The Brain', 'want to conquer the world')\nduosWork('Bonnie', 'Clyde', 'escape the Police')\nduosWork('Mr.', 'Mrs.Smith', 'are the greatest spy couple')\n\nequal(\n args.map(arg => arg.join(' ')),\n [\n 'Batman and Robin protect Gotham !',\n 'Pinky and The Brain want to conquer the world !',\n 'Bonnie and Clyde escape the Police !',\n 'Mr. and Mrs.Smith are the greatest spy couple !',\n ],\n)"
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nduosWork('Batman', 'Robin', 'protect Gotham')\nduosWork('Pinky', 'The Brain', 'want to conquer the world')\nduosWork('Bonnie', 'Clyde', 'escape the Police')\nduosWork('Mr.', 'Mrs.Smith', 'are the greatest spy couple')\n\nequal(\n args.map((arg) => arg.join(' ')),\n [\n 'Batman and Robin protect Gotham !',\n 'Pinky and The Brain want to conquer the world !',\n 'Bonnie and Clyde escape the Police !',\n 'Mr. and Mrs.Smith are the greatest spy couple !',\n ],\n)"
}
]

6
subjects/3-directions/README.md

@ -43,6 +43,12 @@ access them and assign their values to variables:
- a variable `kiss` of an array of 2 elements, the last and the first element of
the `list`, in that order.
**Example:** if `list` is `[1,2,3]`
- `first` would be `1`
- `last` would be `3`
- `kiss` would be `[3, 1]`
> 🧑‍🎤 ............ Oh, ........... 🧑‍🎤
> 🎶 .. I wanna be last, yeah ... 🎶
> 🎵 . Baby let me be your last . 🎵

2
subjects/a-winning-argument/README.md

@ -27,7 +27,7 @@ We are now going to adapt `myFirstFuntion` so that it takes one argument :
`arg1`.
```js
let myFirstFunction = arg1 => {
let myFirstFunction = (arg1) => {
//<-arg1 is inputed in between the parens
console.log(arg1) // arg1 can be use inside the scope of the function
// ↖ arg1 is "transfered" to be the arg of console.log()

38
subjects/about-time/README.md

@ -0,0 +1,38 @@
## About Time
### Instructions
Create the function `ultimateScoreboard` that takes an array of scores, and a
`count` and produce the **ULTIMATE** score board:
- Only show the TOP `count` peoples
- Format durations in `minutes:seconds`
> ex: `123` -> `02:03` (123 seconds = 2 minutes and 3 seconds)
- Format each scores with first the position in the scoreboard from `1`, then
the formated `duration` described previously and finally the name
> ex: `[{ name: 'Wasan', duration: 93 }]` -> `['#01 - 01:33, Wasan']` \
> note that numbers lower than 10 must be padded with a leading 0
**Example**:
```js
let scores = [
{ name: 'Wasan', duration: 93 },
{ name: 'Muntaser', duration: 122 },
{ name: 'Noura', duration: 235 },
{ name: 'Maitha', duration: 927 },
]
let scoreboard = ultimateScoreboard(scores, 3)
console.log(scoreboard) /* [
'#01 - 01:33, Wasan',
'#02 - 02:02, Muntaser',
'#03 - 03:55, Noura',
]
```
> This time, no more instructions, find the steps yourselfs, good luck !

11
subjects/access/README.md

@ -7,10 +7,10 @@ Now that we know how to define objects, let's start to use them
Let's start with getting values from them. Well, turns out you already have been
doing it a lot, remember `console.log` ?
The `.` here is *accessing* the property `log` from the `console` object.
The `.` here is _accessing_ the property `log` from the `console` object.
Taking the previous example `transaction` object, we can access properties
from it using `.` same way we got the `log` function:
Taking the previous example `transaction` object, we can access properties from
it using `.` same way we got the `log` function:
```js
let transaction = {
@ -23,9 +23,8 @@ console.log(transaction) // Will log the whole transaction
console.log(transaction.amount) // will only log the amount of the transaction
```
Accessing a property with `.` only give you it's value, and
because it is a value you can use it like any other values:
Accessing a property with `.` only give you it's value, and because it is a
value you can use it like any other values:
```js
let taxes = 1.2 // let's define 20% taxes

21
subjects/give-me-the-code/README.md

@ -0,0 +1,21 @@
## Give me the code
### Instructions
Create a `jsFileOnly` function that takes an array of filenames (strings) and
only keeps those that are ending with `.js`
**Example:**
```js
const result = jsFileOnly([
'essay.docx',
'index.html',
'info.txt',
'lib.js',
'README.md',
'script.js',
])
console.log(result) // ['lib.js', 'script.js']
```

15
subjects/half-a-million/README.md

@ -44,10 +44,19 @@ variables:
- a `vault` object
- a `secret` string
You must use the `secret` value as a key to access the matching value from the
`vault` and assign it to a variable `loot`.
Your goal is to steal the `secret` matching value from the `vault`.
You must then replace the value from the vault by a message of your choice.
Declare a variable `loot` and assign it's value using the variable `secret`
value as a key to access the matching value from the `vault`.
You must then replace the value from the vault's secret by a message of your
choice.
**Example**: if `vault` is `{ '53CR37-k0D3': '1/2 MM $' }` and `secret` is
`'53CR37-k0D3'`:
- `loot` should be `1/2 MM $`
- `vaut` should be `{ '53CR37-k0D3': 'I stole your $$' }`
> I sure hope you didn't do anything stupid, Jackie. \
> ― Ray Nicolette

17
subjects/jaden-case/README.md

@ -0,0 +1,17 @@
## Jaden Case
### Instructions
Declare a `toJadenCase` function that takes a string `sentence` argument and
does:
- `.split` the `sentence` argument into words
- then `.map` over it to capitalize each words
- finally `.join` the capitalized words back into a sentence
**Example**:
```js
let result = toJadenCase('there is no dress')
console.log(result) // > 'There Is No Dress'
```

8
subjects/keep/README.md

@ -10,6 +10,12 @@ of all the characters in an alphabet:
- Declare a `keepFirstLast` variable of the 3 first characters and 4 last
characters from `alphabet`.
> **Example:** if `alphabet` value is `'abcdefghijklmnopqrstuvwxyz'`
>
> - `keepFirst` must be `'abcdef'`
> - `keepLast` must be `'tuvwxyz'`
> - `keepFirstLast` must be `'abcwxyz'`
### Notions
- [devdocs.io/javascript/global_objects/string/slice](https://devdocs.io/javascript/global_objects/string/slice)
- [Slice](https://devdocs.io/javascript/global_objects/string/slice)

4
subjects/level-up/README.md

@ -16,8 +16,8 @@ let happy = (mood) => {
let result1 = happy('happy')
let result2 = happy('sad')
console.log(result1) //true
console.log(result2) //false
console.log(result1) // true
console.log(result2) // false
```
Here we used the `if` statement, and two `return` keywords to alternate between

43
subjects/names-plz/README.md

@ -0,0 +1,43 @@
## Names plz
### Chaining methods
One common pattern in javascript is to chain methods to achieve a specific goal:
```js
let title = 'Title: THE MATRIX '
.slice(6) // ' THE MATRIX '
.trim() // 'THE MATRIX'
.toLowerCase() // 'the matrix'
.replace(' ', '-') // 'the-matrix'
// Final result:
console.log(title) // 'the-matrix'
```
This is an example of a chaining 4 different methods to transform the original
string `'Title: THE MATRIX '` into `'the-matrix'`.
### Instructions
It's now your turn to chain methods!
Declare a `namePlz` function that takes an array of objects with a `.name`
string property and does:
- `.map` form objects to get only the property `name`
- `.join` each names with a `,` and a space
**Example:**
```js
const result = namePlz([
{ name: 'Wasan' },
{ name: 'Alanoud' },
{ name: 'Salama' },
{ name: 'Yousuf' },
{ name: 'Maitha' },
])
console.log(result) // 'Wasan, Alanoud, Salama, Yousuf, Maitha'
```

44
subjects/no-adults-wanted/README.md

@ -0,0 +1,44 @@
## No Adults Wanted
### `filter`
In JS most of the time, a loop is not needed and specials array methods can help
doing the heavy work.
The first one we are going to see is the `filter` array method:
```js
let values = [1, 23, 3, 43, 78, 9, 23, 12]
let isOver20 = (value) => {
if (value > 20) {
return true
}
}
let valuesUnder10 = values.filter(isOver20)
console.log(valuesUnder10) // [23, 43, 78, 23]
```
In this case, `values` is an array and the `.filter` method is used to filter
only those that are over `20`.
This is achieved by giving `filter` a special function that will return `true`
if we want to keep this value or not.
Filtering is the best way to remove elements from an array, when you only need
to do a selection but not modify them.
### Instructions
Create a function `childrenOnly` that takes an array of numbers and returns only
those that are lower than 18
**Example:**
```js
const result = childrenOnly([12, 11, 23, 44, 10])
console.log(result) // [12, 11, 10]
```

3
subjects/recursion/README.md

@ -0,0 +1,3 @@
## 🌟 Recursion
### Instructions

34
subjects/speed-run/README.md

@ -0,0 +1,34 @@
## Speed run
### Instructions
You are making the score board of a speed run event.
Speed running means doing something (usually a game) in the least amount of time
possible.
Declare a function `scoreboard` that takes an array of `scores`
Each `score` is an object with 2 properties:
- `name` the name of the participant
- `duration` the duration of the performance of the participant (in seconds)
Operations that must be done by your function:
- Use `.filter` to only select `scores` with a `duration` lower than 12 minutes
- Use `.map` format each results in a string
> format example: `{ name: 'Noura', duration: 235 }` -> `Noura, 235 seconds`
**Complete Example**:
```js
let result = scoreboard([
{ name: 'Noura', duration: 235 },
{ name: 'Maitha', duration: 927 },
{ name: 'Muntaser', duration: 122 },
])
console.log(result) // ['Noura, 235 seconds', 'Muntaser, 122 seconds']
```

48
subjects/squared/README.md

@ -0,0 +1,48 @@
## Squared
`.filter` is not the only useful array method that do loops for you.
### `map`
The `.map` method is another very powerful tool once mastered, let's see it in
action:
```js
const time10 = [1, 2, 3, 4, 5].map((num) => {
return `#${num}`
})
console.log(time10) // [`#1`, `#2`, `#3`, `#4`, `#5`]
```
Map takes a function and apply it to each elements of the array.
Note that map will never change the number of element of the array
For example if your function return nothing:
```js
const nothingX3 = [1, 2, 3].map((num) => {
// Not doing anything today...
})
console.log(nothingX3) // [undefined, undefined, undefined]
```
We still get an array of 3 elements, but they are `undefined`.
You should use map everytime you want to repeat the same action for all
elements.
### Instructions
Declare a function `toSquares` that takes an array of numbers and return an
array of those squared numbers
**Example:**
```js
const result = toSquares([1, 2, 3, 4])
console.log(result) // [1, 4, 9, 16]
```

4
subjects/swapy/README.md

@ -46,7 +46,7 @@ Now my array look like this:
Example:
```js
let replaceMe = ['pif','paf','pom']
let replaceMe = ['pif', 'paf', 'pom']
// expect -> ['pif','paf','great']
```
@ -55,7 +55,7 @@ let replaceMe = ['pif','paf','pom']
Example:
```js
let swapMe = ['pif','paf','pom']
let swapMe = ['pif', 'paf', 'pom']
// expect -> ['paf','pif','pom'] (last element is untouched)
```

Loading…
Cancel
Save