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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
Binary file added docs/.DS_Store
Binary file not shown.
Binary file added docs/Exercise/.DS_Store
Binary file not shown.
Binary file added docs/Exercise/JavaScript_Basics/.DS_Store
Binary file not shown.
16 changes: 16 additions & 0 deletions docs/Exercise/JavaScript_Basics/number_method.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
1. Write a JavaScript function that reverse a number. Go to the editor
Example x = 32243;
Expected Output : 34223

2. Write a JavaScript function that accepts a number as a parameter and check the number is prime or not.
Note : A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.

3.Write a JavaScript function which says whether a number is perfect.
According to Wikipedia : In number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself (also known as its aliquot sum). Equivalently, a perfect number is a number that is half the sum of all of its positive divisors (including itself).
Example : The first perfect number is 6, because 1, 2, and 3 are its proper positive divisors, and 1 + 2 + 3 = 6. Equivalently, the number 6 is equal to half the sum of all its positive divisors: ( 1 + 2 + 3 + 6 ) / 2 = 6. The next perfect number is 28 = 1 + 2 + 4 + 7 + 14. This is followed by the perfect numbers 496 and 8128.

4.Write a JavaScript function to compute the factors of a positive integer.

5. Write a JavaScript function that converts number into exponential notation.

6. Write a Javascript function which writes number with a specified number of decimals.
52 changes: 52 additions & 0 deletions docs/Exercise/JavaScript_Basics/regex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
1. Write a JavaScript program to test the first character of a string is uppercase or not.
Expected Answer:
```js
regexp = /^[A-Z]/;
```
2. Write a JavaScript program to check a credit card number.
Expected Answer:
```js
regexp = /^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/
```

3. Write a pattern that matches e-mail addresses.
The personal information part contains the following ASCII characters.
Uppercase (A-Z) and lowercase (a-z) English letters.
Digits (0-9).
Characters ! # $ % & * + - / = ? ^ _ { | } ~
Character . ( period, dot or fullstop) provided that it is not the first or last character and it will not come one after the other.

Expected Answer:
```js regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/```

4. Write a JavaScript program to search a date within a string.
Expected Answer:
```js regexp = /^(1[0-2]|0?[1-9])\/(3[01]|[12][0-9]|0?[1-9])\/(?:[0-9]{2})?[0-9]{2}$/;```

5. Write a JavaScript program that work as a trim function (string) using regular expression.
Expected Answer:
```js result = str.replace(/^\s+|\s+$/g, '');```

6. Write a JavaScript program to count number of words in string.
Note :
- Remove white-space from start and end position.
- Convert 2 or more spaces to 1.
- Exclude newline with a start spacing.

Expected Answer:
```js
function count_words()
{
str1= document.getElementById("InputText").value;

//exclude start and end white-space
str1 = str1.replace(/(^\s*)|(\s*$)/gi,"");

//convert 2 or more spaces to 1
str1 = str1.replace(/[ ]{2,}/gi," ");
// exclude newline with a start spacing
str1 = str1.replace(/\n /,"\n");
document.getElementById("noofwords").value = str1.split(' ').length;
}
```