From cf49b19dfcd267932c6099ff1e5255f5a7df4dfd Mon Sep 17 00:00:00 2001 From: Katwal Devendra Date: Tue, 2 Apr 2019 13:35:31 +0300 Subject: [PATCH 1/4] array solution 1 --- students/devendra-katwal/ex1.js | 15 +++++++++++++++ students/devendra-katwal/ex2.js | 11 +++++++++++ students/devendra-katwal/ex3.js | 10 ++++++++++ students/devendra-katwal/ex4.js | 9 +++++++++ 4 files changed, 45 insertions(+) create mode 100644 students/devendra-katwal/ex1.js create mode 100644 students/devendra-katwal/ex2.js create mode 100644 students/devendra-katwal/ex3.js create mode 100644 students/devendra-katwal/ex4.js diff --git a/students/devendra-katwal/ex1.js b/students/devendra-katwal/ex1.js new file mode 100644 index 0000000..4359b12 --- /dev/null +++ b/students/devendra-katwal/ex1.js @@ -0,0 +1,15 @@ +/* +Write a JavaScript function to check whether an input is an array or not. + +Test Data : +console.log(isArray('w3resource')); // false +console.log(isArray([1, 2, 4, 0])); // true +*/ + + + +function isArray(input){ + return Array.isArray(input) +} +console.log(isArray('w3resource')); // false +console.log(isArray([1, 2, 4, 0])); // true \ No newline at end of file diff --git a/students/devendra-katwal/ex2.js b/students/devendra-katwal/ex2.js new file mode 100644 index 0000000..eb24fa7 --- /dev/null +++ b/students/devendra-katwal/ex2.js @@ -0,0 +1,11 @@ +/* +Write a JavaScript function to get the first element of an array. Passing a parameter 'n' will return the first 'n' elements of the array. + +Test Data :  +console.log(first([7, 9, 0, -2])); // 7 +console.log(first([],3)); // [] +console.log(first([7, 9, 0, -2],3)); // [7,9,0] +console.log(first([7, 9, 0, -2],6)); // [7, 9, 0, -2] +console.log(first([7, 9, 0, -2],-3)); // [] + +*/ \ No newline at end of file diff --git a/students/devendra-katwal/ex3.js b/students/devendra-katwal/ex3.js new file mode 100644 index 0000000..eb98a2a --- /dev/null +++ b/students/devendra-katwal/ex3.js @@ -0,0 +1,10 @@ +/* +Write a simple JavaScript program to join all elements of the following array into a string. + +Sample array : +var myText = ['This', 'is', 'not', 'working']; +joinArray(myText); + +Expected Output :  +This is not working + */ \ No newline at end of file diff --git a/students/devendra-katwal/ex4.js b/students/devendra-katwal/ex4.js new file mode 100644 index 0000000..72f98cc --- /dev/null +++ b/students/devendra-katwal/ex4.js @@ -0,0 +1,9 @@ +/* +ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but exactly 4 digits or exactly 6 digits. If the function is passed a valid PIN string, return true, else return false. + +validatePIN(1234); // false +validatePIN(00004324); // false +validatePIN('2312'); // true +validatePin('asd123'); // false +validatePin('000010'); // true + */ \ No newline at end of file From 650e004525d8448b6114fb0806d36c0e64e94634 Mon Sep 17 00:00:00 2001 From: Katwal Devendra Date: Tue, 2 Apr 2019 14:33:36 +0300 Subject: [PATCH 2/4] array answer --- students/devendra-katwal/ex2.js | 20 +++++++++++++++++++- students/hoang-pham/copy-and-rename/ex1.js | 9 +++++++++ students/hoang-pham/copy-and-rename/ex2.js | 11 +++++++++++ students/hoang-pham/copy-and-rename/ex3.js | 10 ++++++++++ students/hoang-pham/copy-and-rename/ex4.js | 9 +++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 students/hoang-pham/copy-and-rename/ex1.js create mode 100644 students/hoang-pham/copy-and-rename/ex2.js create mode 100644 students/hoang-pham/copy-and-rename/ex3.js create mode 100644 students/hoang-pham/copy-and-rename/ex4.js diff --git a/students/devendra-katwal/ex2.js b/students/devendra-katwal/ex2.js index eb24fa7..edd0c14 100644 --- a/students/devendra-katwal/ex2.js +++ b/students/devendra-katwal/ex2.js @@ -8,4 +8,22 @@ console.log(first([7, 9, 0, -2],3)); // [7,9,0] console.log(first([7, 9, 0, -2],6)); // [7, 9, 0, -2] console.log(first([7, 9, 0, -2],-3)); // [] -*/ \ No newline at end of file +*/ + +function first(arr, n){ + if(arr.length === 0){ + return [] + }else if (arguments.length>1){ + return arr.splice(0,n) + }else if (arr.length ===1){ + return arr + }else if (n === null || n === 'undefined'){ + return arr[0] + } +} +console.log(first([7, 9, 0, -2])); // 7 +console.log(first([],3)); // [] +console.log(first([7, 9, 0, -2],3)); // [7,9,0] +console.log(first([7, 9, 0, -2],6)); // [7, 9, 0, -2] +console.log(first([7, 9, 0, -2],-3)); // [] +console.log(first([7, 9, 0, -2],'undefined')); // [] \ No newline at end of file diff --git a/students/hoang-pham/copy-and-rename/ex1.js b/students/hoang-pham/copy-and-rename/ex1.js new file mode 100644 index 0000000..1c7fc89 --- /dev/null +++ b/students/hoang-pham/copy-and-rename/ex1.js @@ -0,0 +1,9 @@ +/* +Write a JavaScript function to check whether an input is an array or not. + +Test Data : +console.log(isArray('w3resource')); // false +console.log(isArray([1, 2, 4, 0])); // true +*/ + + diff --git a/students/hoang-pham/copy-and-rename/ex2.js b/students/hoang-pham/copy-and-rename/ex2.js new file mode 100644 index 0000000..eb24fa7 --- /dev/null +++ b/students/hoang-pham/copy-and-rename/ex2.js @@ -0,0 +1,11 @@ +/* +Write a JavaScript function to get the first element of an array. Passing a parameter 'n' will return the first 'n' elements of the array. + +Test Data :  +console.log(first([7, 9, 0, -2])); // 7 +console.log(first([],3)); // [] +console.log(first([7, 9, 0, -2],3)); // [7,9,0] +console.log(first([7, 9, 0, -2],6)); // [7, 9, 0, -2] +console.log(first([7, 9, 0, -2],-3)); // [] + +*/ \ No newline at end of file diff --git a/students/hoang-pham/copy-and-rename/ex3.js b/students/hoang-pham/copy-and-rename/ex3.js new file mode 100644 index 0000000..eb98a2a --- /dev/null +++ b/students/hoang-pham/copy-and-rename/ex3.js @@ -0,0 +1,10 @@ +/* +Write a simple JavaScript program to join all elements of the following array into a string. + +Sample array : +var myText = ['This', 'is', 'not', 'working']; +joinArray(myText); + +Expected Output :  +This is not working + */ \ No newline at end of file diff --git a/students/hoang-pham/copy-and-rename/ex4.js b/students/hoang-pham/copy-and-rename/ex4.js new file mode 100644 index 0000000..72f98cc --- /dev/null +++ b/students/hoang-pham/copy-and-rename/ex4.js @@ -0,0 +1,9 @@ +/* +ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but exactly 4 digits or exactly 6 digits. If the function is passed a valid PIN string, return true, else return false. + +validatePIN(1234); // false +validatePIN(00004324); // false +validatePIN('2312'); // true +validatePin('asd123'); // false +validatePin('000010'); // true + */ \ No newline at end of file From 7b6df7be3b50e8569809dfc8f134f8f78588e5a3 Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 3 Apr 2019 09:53:23 +0300 Subject: [PATCH 3/4] solved 4) --- students/devendra-katwal/ex3.js | 7 ++++++- students/devendra-katwal/ex4.js | 20 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/students/devendra-katwal/ex3.js b/students/devendra-katwal/ex3.js index eb98a2a..6a90f05 100644 --- a/students/devendra-katwal/ex3.js +++ b/students/devendra-katwal/ex3.js @@ -7,4 +7,9 @@ joinArray(myText); Expected Output :  This is not working - */ \ No newline at end of file +*/ +function joinArray(myText){ + return myText.join(' ') +} + +console.log(joinArray(['This', 'is', 'not', 'working'])); \ No newline at end of file diff --git a/students/devendra-katwal/ex4.js b/students/devendra-katwal/ex4.js index 72f98cc..1585ddb 100644 --- a/students/devendra-katwal/ex4.js +++ b/students/devendra-katwal/ex4.js @@ -1,9 +1,25 @@ /* -ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but exactly 4 digits or exactly 6 digits. If the function is passed a valid PIN string, return true, else return false. +ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but exactly 4 digits +or exactly 6 digits. If the function is passed a valid PIN string, return true, else return false. validatePIN(1234); // false validatePIN(00004324); // false validatePIN('2312'); // true validatePin('asd123'); // false validatePin('000010'); // true - */ \ No newline at end of file +*/ +function validatePIN(input){ + if(input.length === 4 || input.length === 6 && !isNaN(input)){ + return true + }else { + return false + } +} + +console.log(validatePIN(1234)); // false +console.log(validatePIN(00004324)); // false +console.log(validatePIN('2312')); // true +console.log(validatePIN('asd123')); // false +console.log(validatePIN('000010')); // true + + From 71830932bcae8a76d5ee5295414807778a35fcdb Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 3 Apr 2019 09:58:14 +0300 Subject: [PATCH 4/4] fixed semi colon --- students/devendra-katwal/ex1.js | 2 +- students/devendra-katwal/ex2.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/students/devendra-katwal/ex1.js b/students/devendra-katwal/ex1.js index 4359b12..d7c64cc 100644 --- a/students/devendra-katwal/ex1.js +++ b/students/devendra-katwal/ex1.js @@ -9,7 +9,7 @@ console.log(isArray([1, 2, 4, 0])); // true function isArray(input){ - return Array.isArray(input) + return Array.isArray(input); } console.log(isArray('w3resource')); // false console.log(isArray([1, 2, 4, 0])); // true \ No newline at end of file diff --git a/students/devendra-katwal/ex2.js b/students/devendra-katwal/ex2.js index edd0c14..0f14140 100644 --- a/students/devendra-katwal/ex2.js +++ b/students/devendra-katwal/ex2.js @@ -12,13 +12,13 @@ console.log(first([7, 9, 0, -2],-3)); // [] function first(arr, n){ if(arr.length === 0){ - return [] + return []; }else if (arguments.length>1){ - return arr.splice(0,n) + return arr.splice(0,n); }else if (arr.length ===1){ - return arr + return arr; }else if (n === null || n === 'undefined'){ - return arr[0] + return arr[0]; } } console.log(first([7, 9, 0, -2])); // 7