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
15 changes: 15 additions & 0 deletions students/devendra-katwal/ex1.js
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions students/devendra-katwal/ex2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
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)); // []

*/

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')); // []
15 changes: 15 additions & 0 deletions students/devendra-katwal/ex3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
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
*/
function joinArray(myText){
return myText.join(' ')
}

console.log(joinArray(['This', 'is', 'not', 'working']));
25 changes: 25 additions & 0 deletions students/devendra-katwal/ex4.js
Original file line number Diff line number Diff line change
@@ -0,0 +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.

validatePIN(1234); // false
validatePIN(00004324); // false
validatePIN('2312'); // true
validatePin('asd123'); // false
validatePin('000010'); // true
*/
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


9 changes: 9 additions & 0 deletions students/hoang-pham/copy-and-rename/ex1.js
Original file line number Diff line number Diff line change
@@ -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
*/


11 changes: 11 additions & 0 deletions students/hoang-pham/copy-and-rename/ex2.js
Original file line number Diff line number Diff line change
@@ -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)); // []

*/
10 changes: 10 additions & 0 deletions students/hoang-pham/copy-and-rename/ex3.js
Original file line number Diff line number Diff line change
@@ -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
*/
9 changes: 9 additions & 0 deletions students/hoang-pham/copy-and-rename/ex4.js
Original file line number Diff line number Diff line change
@@ -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
*/