10 Things That I have learned During Problem Solving.
Today I learned this 10 things.
1) parseInt():
The parseInt() function parses a string and returns an integer.
const parsed = parseInt(x, base);
2) parseFloat()
The parseFloat() function parses an argument and returns a floating point number.
3) Factorial:
The factorial function says to multiply all whole numbers from our chosen number down to 1.
Examples:
4! = 4 × 3 × 2 × 1 = 247! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 50401! = 1
4) Recursive Method:
Recursive function is a function that call itself until it reaches a threshold value.
function factorial(n) {if(n===0) return 1;return n*factorial(n-1);}
5) Math.PI :
The Math. PI is a property in JavaScript which is simply used to find the value of Pi i.e, in symbolic form Π which is nothing but it is the ratio of the circumference of a circle to its diameter, whose value is approximately 3.141
6) Multiple Switch:
We can define a singe scope for multiple cases if needed.
Example:
switch(condition) {
case “a”:
case “e”:
case “i”:
case “o”:
case “u”:
return “A”;
break;
7) Regular expressions:
Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects.
Example:
. => Find a single character, except newline or line terminator\w => Find a word character\W =>Find a non-word character\d =>Find a digit\D => Find a non-digit character\s =>Find a whitespace character\S =>Find a non-whitespace character\b =>Find a match at the beginning/end of a word, beginning like this: \bHI, end like this: HI\b
8) readline():
Readline function is their method to read stdin and print() is the stdout method.
var name = readline();
9)Array.sort():
arr.sort() function is used to sort the array.
var nums =[2,9,3,8,9,8,6,4]nums = nums.sort();console.log(nums);//output: [2,3,4,6,8,8,9,9]
10)throw():
The throw
statement throws a user-defined exception.
Example:
if( conditions === true){///execute this code}else{throw(new Error(“error message”))}
Thanks for reading.