diff --git a/src/ex1_js-basics-part1/task-01.js b/src/ex1_js-basics-part1/task-01.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/ex2_js-basics-part2/task-01.js b/src/ex2_js-basics-part2/task-01.js new file mode 100644 index 000000000..25b59c7e8 --- /dev/null +++ b/src/ex2_js-basics-part2/task-01.js @@ -0,0 +1,10 @@ +function checkType(primitive) { + if (isNaN(primitive)) { + return undefined; + } + + if (typeof primitive === 'string' | 'number') { + return typeof primitive; + } +} +module.exports = checkType; diff --git a/src/ex2_js-basics-part2/task-02.js b/src/ex2_js-basics-part2/task-02.js new file mode 100644 index 000000000..e152b29ae --- /dev/null +++ b/src/ex2_js-basics-part2/task-02.js @@ -0,0 +1,7 @@ +function arrayCheck(array) { + for (let i = 0; i < array.length; i++) { + console.log(i); + } + console.log(array.length); +} +module.exports = arrayCheck; diff --git a/src/ex2_js-basics-part2/task-03.js b/src/ex2_js-basics-part2/task-03.js new file mode 100644 index 000000000..e23d52fb6 --- /dev/null +++ b/src/ex2_js-basics-part2/task-03.js @@ -0,0 +1,49 @@ +function isNumber(number) { + if (typeof number === 'number') { + return true; + } + return false; +} +module.exports = isNumber; +function arrayCheckIsEven(array) { + let counter = 0; + for (let i = 0; i < array.length; i++) { + if (isNumber(array[i]) && array[i] !== 0) { + if (array[i] % 2 === 0) { + counter += 1; + } + } + } + return counter; +} +module.exports = arrayCheckIsEven; +function arrayCheckIsOdd(array) { + let counter = 0; + for (let i = 0; i < array.length; i++) { + if (isNumber(array[i]) && array[i] !== 0) { + if (array[i] % 2 === 1 || array[i] === 1) { + counter += 1; + } + } + } + return counter; +} +module.exports = arrayCheckIsOdd; +function arrayCheckIsZero(array) { + let counter = 0; + for (let i = 0; i < array.length; i++) { + if (isNumber(array[i])) { + if (array[i] === 0) { + counter += 1; + } + } + } + return counter; +} +module.exports = arrayCheckIsZero; +function arrayCheckParity(array) { + const result = [arrayCheckIsEven(array), arrayCheckIsOdd(array), arrayCheckIsZero(array)]; + + return result; +} +module.exports = arrayCheckParity; diff --git a/src/ex2_js-basics-part2/task-04.js b/src/ex2_js-basics-part2/task-04.js new file mode 100644 index 000000000..ce962eda5 --- /dev/null +++ b/src/ex2_js-basics-part2/task-04.js @@ -0,0 +1,13 @@ +function arrayCheckSimilar(array) { + for (let i = 0; i < array.length; i++) + if (typeof array[i]==='number') { + for (let j = i+1; j < array.length; j++) { +if (array[i]===array[j]) { + return true; + } + + } +} +return false; +} +module.exports = arrayCheckSimilar; diff --git a/src/ex2_js-basics-part2/task-05.js b/src/ex2_js-basics-part2/task-05.js new file mode 100644 index 000000000..f3a04db9e --- /dev/null +++ b/src/ex2_js-basics-part2/task-05.js @@ -0,0 +1,9 @@ +function arrayFindkMax(array) { + let max = 0; + const a = array.length; + for (let i = 0; i < a; i++) { + if (array[i] > max) { max = array[i]; } + } + return max; +} +module.exports = arrayFindkMax;