mirror of https://github.com/01-edu/public.git
Clement Denis
4 years ago
24 changed files with 395 additions and 21 deletions
@ -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)" |
||||
} |
||||
] |
@ -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)" |
||||
} |
||||
] |
@ -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}" |
||||
} |
||||
] |
@ -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)" |
||||
} |
||||
] |
@ -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([]), '')" |
||||
} |
||||
] |
@ -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])" |
||||
} |
||||
] |
@ -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)" |
||||
} |
||||
] |
@ -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])" |
||||
} |
||||
] |
@ -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 ! |
@ -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'] |
||||
``` |
@ -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' |
||||
``` |
@ -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' |
||||
``` |
@ -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] |
||||
``` |
@ -0,0 +1,3 @@
|
||||
## 🌟 Recursion |
||||
|
||||
### Instructions |
@ -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'] |
||||
``` |
@ -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] |
||||
``` |
Loading…
Reference in new issue