Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
10 changes: 10 additions & 0 deletions src/ex2_js-basics-part2/task-01.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function checkType(primitive) {
if (isNaN(primitive)) {
return undefined;
}

if (typeof primitive === 'string' | 'number') {
return typeof primitive;
}
}
module.exports = checkType;
7 changes: 7 additions & 0 deletions src/ex2_js-basics-part2/task-02.js
Original file line number Diff line number Diff line change
@@ -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;
49 changes: 49 additions & 0 deletions src/ex2_js-basics-part2/task-03.js
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 13 additions & 0 deletions src/ex2_js-basics-part2/task-04.js
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 9 additions & 0 deletions src/ex2_js-basics-part2/task-05.js
Original file line number Diff line number Diff line change
@@ -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;