Browse Source

js exercises: mutability merge

content-update
lee 4 years ago committed by Clément
parent
commit
b52f5cb684
  1. 22
      js/tests/id_test.js
  2. 15
      js/tests/mutable.js
  3. 10
      subjects/id.en.md
  4. 9
      subjects/mutable.en.md

22
js/tests/id_test.js

@ -1,22 +0,0 @@
export const tests = []
const t = (f) => tests.push(f)
// id is declared and is a function
t(() => typeof id === 'function')
// id take 1 argument
t(() => id.length === 1)
// id return numbers back
t(() => id(5) === 5)
// id return strings back
t(() => id('pouet') === 'pouet')
// id return itself, why not
t(() => id(id) === id)
// id return anything really
t((_) => id(_) === _)
Object.freeze(tests)

15
js/tests/get-length_test.js → js/tests/mutable.js

@ -1,12 +1,23 @@
export const tests = []
const t = (f) => tests.push(f)
// id is declared and is a function
t(() => typeof id === 'function')
// id take 1 argument
t(() => id.length === 1)
// id return numbers back
t(() => id(5) === 5)
// id return strings back
t(() => id('pouet') === 'pouet')
// id return itself, why not
t(() => id(id) === id)
// id return anything really
t((_) => id(_) === _)
// handle simple array
t(() => getLength([2, 42]) === 2)
// handle mixed array
t(() => getLength(['pouet', 4, true]) === 3)
t(() => getLength(Array(100)) === 100) // handle holey array
t(() => getLength('salut') === 5) // handle strings
t(() => getLength([]) === 0) // handle empty arrays

10
subjects/id.en.md

@ -1,10 +0,0 @@
## Id
### Instructions
Create an `id` function that takes one argument and return it
### Notions
- [https://nan-academy.github.io/js-training/examples/functions.js](https://nan-academy.github.io/js-training/examples/functions.js)

9
subjects/get-length.en.md → subjects/mutable.en.md

@ -1,12 +1,15 @@
## Get Length
## mutable
### Instructions
Create a `getLength` function that takes an array or a string
and return its length.
Create the following functions:
- `id` that takes one argument and return it
- `getLength` that takes an array or a string and return its length
### Notions
- [https://nan-academy.github.io/js-training/examples/functions.js](https://nan-academy.github.io/js-training/examples/functions.js)
- [https://nan-academy.github.io/js-training/examples/data-structures.js](https://nan-academy.github.io/js-training/examples/data-structures.js)
- [https://nan-academy.github.io/js-training/examples/get.js](https://nan-academy.github.io/js-training/examples/get.js)
Loading…
Cancel
Save