diff --git a/Task3/question1.js b/Task3/question1.js new file mode 100644 index 0000000..d5204e7 --- /dev/null +++ b/Task3/question1.js @@ -0,0 +1,11 @@ +// http://www.codewars.com/kata/prefill-an-array + +function prefill(n, v) { + + if (isNaN(n) || Number(n) == NaN || n === Infinity || n === -Infinity || n < 0 || typeof(n) == 'boolean' || n % 1 != 0) + throw new TypeError(n + " is invalid"); + else { + arr = (new Array(Number(n))).fill(v); + } + return arr; +} diff --git a/Task3/question2.js b/Task3/question2.js new file mode 100644 index 0000000..35bd745 --- /dev/null +++ b/Task3/question2.js @@ -0,0 +1,7 @@ +// http://www.codewars.com/kata/a-function-within-a-function + +function always(n) { + return function() { + return n + } +} diff --git a/Task3/question3.js b/Task3/question3.js new file mode 100644 index 0000000..963b93b --- /dev/null +++ b/Task3/question3.js @@ -0,0 +1,13 @@ +// http://www.codewars.com/kata/closures-and-scopes/train/javascript + +function createFunctions(n) { + var callbacks = []; + + for (let i = 0; i < n; i++) { + callbacks.push(function() { + return i; + }); + } + + return callbacks; +} diff --git a/Task3/question4.js b/Task3/question4.js new file mode 100644 index 0000000..05baea3 --- /dev/null +++ b/Task3/question4.js @@ -0,0 +1,13 @@ +// http://www.codewars.com/kata/can-you-keep-a-secret + +function createSecretHolder(secret) { + return { + sec: secret, + getSecret: function() { + return this.sec; + }, + setSecret: function(b) { + this.sec = b; + } + } +}