diff --git a/students/aryal/ex1.js b/students/aryal/ex1.js new file mode 100644 index 0000000..1c7fc89 --- /dev/null +++ b/students/aryal/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/aryal/ex2.js b/students/aryal/ex2.js new file mode 100644 index 0000000..bc61230 --- /dev/null +++ b/students/aryal/ex2.js @@ -0,0 +1,32 @@ +/* +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 get_the_value(array, n) { + if(array === null){ + return 0; + } + else if (n === null){ + return [0]; + } + else if (n < 0){ + return []; + } + else { + return array.slice(0, n); + } +} + +console.log(get_the_value([7, 90, 7])); +console.log(get_the_value([2,8,7,8,9],2)) + + + + diff --git a/students/aryal/ex3.js b/students/aryal/ex3.js new file mode 100644 index 0000000..ff3be1a --- /dev/null +++ b/students/aryal/ex3.js @@ -0,0 +1,23 @@ +/* +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(input){ + var index = 0, + result = ' '; + while (index