From f2e91d469a3f7b70d1b549ec389d58600c917217 Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 4 Jun 2020 15:29:59 +0100 Subject: [PATCH] js exercises: declaration merge --- js/tests/arr_test.js | 9 ----- js/tests/declarations.js | 75 +++++++++++++++++++++++++++++++++++++ js/tests/escape-str_test.js | 22 ----------- js/tests/nested_test.js | 39 ------------------- js/tests/obj_test.js | 22 ----------- subjects/arr.en.md | 11 ------ subjects/declarations.en.md | 25 +++++++++++++ subjects/escape-str.en.md | 17 --------- subjects/nested.en.md | 15 -------- subjects/obj.en.md | 15 -------- 10 files changed, 100 insertions(+), 150 deletions(-) delete mode 100644 js/tests/arr_test.js create mode 100644 js/tests/declarations.js delete mode 100644 js/tests/escape-str_test.js delete mode 100644 js/tests/nested_test.js delete mode 100644 js/tests/obj_test.js delete mode 100644 subjects/arr.en.md create mode 100644 subjects/declarations.en.md delete mode 100644 subjects/escape-str.en.md delete mode 100644 subjects/nested.en.md delete mode 100644 subjects/obj.en.md diff --git a/js/tests/arr_test.js b/js/tests/arr_test.js deleted file mode 100644 index 7040e10d..00000000 --- a/js/tests/arr_test.js +++ /dev/null @@ -1,9 +0,0 @@ -export const tests = [] -const t = (f) => tests.push(f) - -t(() => Array.isArray(arr)) // arr is declared and is an array -t(({ eq }) => eq(arr[0], 4)) // arr first element is 4 -t(({ eq }) => eq(arr[1], '2')) // arr second element is "2" -t(({ eq }) => eq(arr.length, 2)) // arr length is 2 - -Object.freeze(tests) diff --git a/js/tests/declarations.js b/js/tests/declarations.js new file mode 100644 index 00000000..53d1ed9a --- /dev/null +++ b/js/tests/declarations.js @@ -0,0 +1,75 @@ +export const tests = [] +const t = (f) => tests.push(f) + +// escapeStr +// is declared and of type string +t(() => typeof escapeStr === 'string') +// should include the character ' +t(() => escapeStr.includes("'")) +// should include the character " +t(() => escapeStr.includes('"')) +// should include the character ` +t(() => escapeStr.includes('`')) +// should include the character / +t(() => escapeStr.includes('/')) +// should include the character \ +t(() => escapeStr.includes('\\')) + +// arr +t(() => Array.isArray(arr)) // arr is declared and is an array +t(({ eq }) => eq(arr[0], 4)) // arr first element is 4 +t(({ eq }) => eq(arr[1], '2')) // arr second element is "2" +t(({ eq }) => eq(arr.length, 2)) // arr length is 2 + +// obj +// obj is declared and of type object +t(() => obj.constructor === Object) +// obj is constant and can not be re-assigned +t(({ fail }) => obj && fail(() => (obj = 10))) +// obj.str is of type string +t(() => typeof obj.str === 'string') +// obj.num is of type number +t(() => typeof obj.num === 'number') +// obj.bool is of type boolean +t(() => typeof obj.bool === 'boolean') +// obj.undef is of type undefined +t(() => 'undef' in obj && typeof obj.undef === 'undefined') + +// nested +const cantEdit = (fn) => { + try { + fn() + } catch (err) { + return true + } +} + +t(() => nested.constructor === Object) + +// nested is constant and can not be re-assigned +t(({ fail }) => nested && fail(() => (nested = 10))) + +t(() => nested.obj.constructor === Object) +t(() => typeof nested.obj.str === 'string') +t(() => typeof nested.obj.num === 'number') +t(() => typeof nested.obj.bool === 'boolean') + +t(() => Array.isArray(nested.arr)) +t(() => nested.arr[0] === 4) +t(() => nested.arr[1] === undefined) +t(() => nested.arr[2] === '2') +t(() => nested.arr.length === 3) + +// nested is frozen and can not be changed +t(() => cantEdit(() => (nested.obj = 5))) +t(() => nested.obj !== 5) + +// nested.obj is also frozen and can not be changed +t(() => cantEdit(() => (nested.obj.update = 5))) +t(() => nested.obj.update === undefined) + +// nested.arr is not frozen and can be changed +t(() => cantEdit(() => nested.arr.push('hot stuff'))) +t(() => nested.arr.length === 3) + +Object.freeze(tests) diff --git a/js/tests/escape-str_test.js b/js/tests/escape-str_test.js deleted file mode 100644 index 8f90603d..00000000 --- a/js/tests/escape-str_test.js +++ /dev/null @@ -1,22 +0,0 @@ -export const tests = [] -const t = (f) => tests.push(f) - -// escapeStr is declared and of type string -t(() => typeof escapeStr === 'string') - -// escapeStr should include the character ' -t(() => escapeStr.includes("'")) - -// escapeStr should include the character " -t(() => escapeStr.includes('"')) - -// escapeStr should include the character ` -t(() => escapeStr.includes('`')) - -// escapeStr should include the character / -t(() => escapeStr.includes('/')) - -// escapeStr should include the character \ -t(() => escapeStr.includes('\\')) - -Object.freeze(tests) diff --git a/js/tests/nested_test.js b/js/tests/nested_test.js deleted file mode 100644 index 6bac5297..00000000 --- a/js/tests/nested_test.js +++ /dev/null @@ -1,39 +0,0 @@ -export const tests = [] -const t = (f) => tests.push(f) -const cantEdit = (fn) => { - try { - fn() - } catch (err) { - return true - } -} - -t(() => nested.constructor === Object) - -// nested is constant and can not be re-assigned -t(({ fail }) => nested && fail(() => (nested = 10))) - -t(() => nested.obj.constructor === Object) -t(() => typeof nested.obj.str === 'string') -t(() => typeof nested.obj.num === 'number') -t(() => typeof nested.obj.bool === 'boolean') - -t(() => Array.isArray(nested.arr)) -t(() => nested.arr[0] === 4) -t(() => nested.arr[1] === undefined) -t(() => nested.arr[2] === '2') -t(() => nested.arr.length === 3) - -// nested is frozen and can not be changed -t(() => cantEdit(() => (nested.obj = 5))) -t(() => nested.obj !== 5) - -// nested.obj is also frozen and can not be changed -t(() => cantEdit(() => (nested.obj.update = 5))) -t(() => nested.obj.update === undefined) - -// nested.arr is not frozen and can be changed -t(() => cantEdit(() => nested.arr.push('hot stuff'))) -t(() => nested.arr.length === 3) - -Object.freeze(tests) diff --git a/js/tests/obj_test.js b/js/tests/obj_test.js deleted file mode 100644 index 14804512..00000000 --- a/js/tests/obj_test.js +++ /dev/null @@ -1,22 +0,0 @@ -export const tests = [] -const t = (f) => tests.push(f) - -// obj is declared and of type object -t(() => obj.constructor === Object) - -// obj is constant and can not be re-assigned -t(({ fail }) => obj && fail(() => (obj = 10))) - -// obj.str is of type string -t(() => typeof obj.str === 'string') - -// obj.num is of type number -t(() => typeof obj.num === 'number') - -// obj.bool is of type boolean -t(() => typeof obj.bool === 'boolean') - -// obj.undef is of type undefined -t(() => 'undef' in obj && typeof obj.undef === 'undefined') - -Object.freeze(tests) diff --git a/subjects/arr.en.md b/subjects/arr.en.md deleted file mode 100644 index 1bbb29bb..00000000 --- a/subjects/arr.en.md +++ /dev/null @@ -1,11 +0,0 @@ -## Arr - -### Instructions - -Create a constant variable named `arr` that is an array -containing the values 4 and '2' - - -### Notions - - - [nan-academy.github.io/js-training/examples/data-structures.js](https://nan-academy.github.io/js-training/examples/data-structures.js) diff --git a/subjects/declarations.en.md b/subjects/declarations.en.md new file mode 100644 index 00000000..baaff926 --- /dev/null +++ b/subjects/declarations.en.md @@ -0,0 +1,25 @@ +## Declarations + +### Instructions + +Create the following variables: + +- `escapeStr`, that contains the following specials characters: \`, `\`, `/`, `"`, `'` +- `arr` that is an array containing the values 4 and '2' +- `obj` that is an object containing a property for each primitives: + - `str` for `String` + - `num` for `Number` + - `bool` for `Boolean` + - `undef` for `undefined` +- `nested` that contains + - arr: an array of the 3 values: 4, undefined, '2' + - obj: an object with 3 property (str, num & bool) + +`nested` and `obj` must be frozen to prevent changes from them. + +### Notions + +- Primitive and Operators +- Variables +- [nan-academy.github.io/js-training/examples/data-structures.js](https://nan-academy.github.io/js-training/examples/data-structures.js) +- [devdocs.io/javascript/global_objects/object/freeze](https://devdocs.io/javascript/global_objects/object/freeze) diff --git a/subjects/escape-str.en.md b/subjects/escape-str.en.md deleted file mode 100644 index c9f30461..00000000 --- a/subjects/escape-str.en.md +++ /dev/null @@ -1,17 +0,0 @@ -## Escape Str - -### Instructions - -Create a constant variable named `escapeStr` that contains -the following specials characters: - - ` - - \ - - / - - " - - ' - - -### Notions - -- Primitive and Operators -- Variables \ No newline at end of file diff --git a/subjects/nested.en.md b/subjects/nested.en.md deleted file mode 100644 index b3fd094b..00000000 --- a/subjects/nested.en.md +++ /dev/null @@ -1,15 +0,0 @@ -## Nested - -### Instructions - -Create a `nested` constant variable that contains -- arr: an array of the 3 values: 4, undefined, '2' -- obj: an object with 3 property (str, num & bool) - -`nested` and `obj` must be frozen to prevent changes from them. - - -### Notions - -- [nan-academy.github.io/js-training/examples/data-structures.js](https://nan-academy.github.io/js-training/examples/data-structures.js) -- [devdocs.io/javascript/global_objects/object/freeze](https://devdocs.io/javascript/global_objects/object/freeze) diff --git a/subjects/obj.en.md b/subjects/obj.en.md deleted file mode 100644 index ec770440..00000000 --- a/subjects/obj.en.md +++ /dev/null @@ -1,15 +0,0 @@ -## Obj - -### Instructions - -Create a constant variable named `obj` that is an object -containing a property for each primitives: -- `str` for `String` -- `num` for `Number` -- `bool` for `Boolean` -- `undef` for `undefined` - - -### Notions - -- [nan-academy.github.io/js-training/examples/data-structures.js](https://nan-academy.github.io/js-training/examples/data-structures.js)