- sum, substraction, multiplication, divison and mod
- Even Odd
- Factorial
- Swap two number
- Swap two number without third variable
- Reverse Number
- Sum of Digit
- Leap Year
- Power of given Number
- Conunt the Digit in a Number
- Random Number Generator
- Factorial Using Recusion
- Fibonacci series
- Fibonacci series Recusion
- Prime number
- All Prime Numbers between 1 to n
- Palindrome number
- Armstrong number
- Strong Number
- Spy Number
- Fahrenheit To
- How to reverse array in place in Java?
- Find Largest Number in an Array
- Find 2nd Largest Number in an Array
- Find 3rd Largest Number in an Array
- Find Smallest Number in an Array
- Find 2nd Smallest Number in an Array
- Find 3rd Smallest Number in an Array
- Remove Duplicate Element in an Array
- Print Odd and Even Number from an Array
- Add Two Matrices
- Multiply Two Matrices
- Transpose matrix
- How to find the missing number in integer array of 1 to 100?
- How to check if String is Palindrome?
- How to remove duplicate characters from String?
- How to Print duplicate characters from String?
- How to check if two Strings are anagrams of each other?
- How to program to print first non repeated character from String?
- How to reverse String in Java using Iteration and Recursion?
- How to check if a String contains only digits?
- How to find duplicate characters in a String?
- How to count number of vowels and consonants in a String?
- How to reverse words in a sentence without using library method?
- Write a program to check if a String contains another String e.g. indexOf()?
- How to return highest occurred character in a String?
- Write a program to remove a given characters from String?
- Write a program to find longest palindrome in a string?
- How to sort String on their length in Java?
- How do you check if two Strings are equal in Java?
- How to Split String in java?
- *
**
***
****
- Bubble Sort
- Selection Sort
- Insertion Sort
- QuickSort
- Linear Search
- Binary Search
- var, let, const
- undefined, null
- Hoisting
soln--> https://scotch.io/tutorials/understanding-hoisting-in-javascript - global object- window, this
- different way to create object and what is the diffenece between all of them.
soln-->> https://coderwall.com/p/p5cf5w/different-ways-of-creating-an-object-in-javascript - copying and cloning and object assign
- constructor, opetator"new"
- map, set, weakmap, and weakset
- recursion and stack
- what data structure is used in recursion
- call/apply/bind
- rest parameters, spread operator, 'arguments' variable
- closure, lexical environment
closure -->> https://scotch.io/tutorials/understanding-javascript-closures-a-practical-approach
Lexical Environment -->> https://scotch.io/turorials/understanding-scope-in-javascript - setTimeout, setInterval, Canceling with clearTimeout, recusive setTimeout
- Currying
- Class, inheritance, super, Overriding a method, overriding constructor
- prototypes, methods for prototypes
soln-->> http://www.javascripttutorial.net/javascript-prototype/ - Property flags and descriptors
- Prototypal inheritance, this
soln-->> http://www.javascriptturorial.net/javascript-prototypal-inheritance/ - Error handling, try, catch, finally
- Event delegation
- Bubbling and capturing
- callbacks, Callback in callback
- Promise, Promises chaining, Returning promises
Basic
String
Object Manipulationn Example
- Calculate total sum of salary
- Store all imgUrl in one array
- Count transaction with customer id and convert into given format
[{cust : x , trans : [x,y]}] - Convert into object of array
['Sonu', 'Vikash','Anshu','Udit', 'Sandeep']
{ 'name': value } - Remove duplicate elememt and convert into object of array
- Convert into object of array
{ 'label': 'Sonu', 'value': 'Sonu' } - Get all name value and convert into object of array
- Merge to object
- Add some property to objrct
- Delete some property to objrct
- String print '5'-5
- What is angular
- Angular JS vs Angular
- Angular Version Histroy
- Architecture of angular application
- Angular Lifecycle hook method
- Starting point of angular application
- What is the use of AOT and JIT
- Difference between aot and jit
- Change detection
- How many type of data binding
- What is decorator, how many type of decorator
- ngIf, ngIfElse, ngIfThen, NgSwitch, NgFor, NgClass, NgStyle, ng-template with ngTemplateOutlet, ngContainer
- Pipe and type of pipe
- how to create custom pipe
- What is directive and type of directive
- how to create custom directive
- Send data from parent to child and child to parent
- If no any relation between any component then how we can set and get the data from one component to another component
- @Viewchild, emitter
- Tpre of form
- What is routing and how to declare
- What is route guard and type of route guard and uses
- What is dependency injection and why we are using
- What is services, why we use it. how to register services
- What is lazy loading
- How to optimize angular application
- Data Binding
- Directives Examples Component, Structural & Attribute
- Event Types for Event Binding
- Create Custom Pipe in Angular
- Creating Custom Directives
- ngIf, ngIfElse, ngIfThen
- NgSwitch
- NgFor
- NgClass and NgStyle
- ng-template with ngTemplateOutlet
- @Input Decorator
- @Output Decorator
- Template deriven form
- Reactive Forms
- ViewChild
- Routes
- Nested Routes
- Child Routes
- HttpClient crud
- Nested Form using FormArray API with Reactive Forms
- Show Image Preview with Reactive Forms
- File Upload with Progress Bar
- JWT User Authentication
- http://csharp-video-tutorials.blogspot.com/
- Angular 9/8 ngIf, ngIfElse, ngIfThen Tutorial with Examples
- Angular 8|9 NgSwitch Directive Tutorial with Examples
- Angular 9/8/7 NgClass and NgStyle Tutorial with Examples
- Displaying Data with Angular 9/8 ngFor Directive
- Angular 8|9 NgClass Directive Tutorial With Example
- Angular 8/9 HttpClient & Http Services Tutorial
- Angular 8/9 HttpClient & Http Services Tutorial
- Build Dynamic HTML Table in Angular 9/8 with ngFor Build Dynamic HTML Table in Angular 9/8 with ngFor
- Unit Testing Angular 9/8 Application with Jasmine & Karma
- Angular 9/8 Form Validation with Template Driven Form using Bootstrap
- Angular 8/9 Service Tutorial with Example
- Angular + PrimeNG Tutorial - Implement DataTable Component
- Primeng with Angular 6 example from scratch with tutorials | Primeng Angular Tutorial Example
- Angular2 PrimeNG Tutorial- Create a hello world application using PrimeNG components.
- Angular2 PrimeNG Tutorial- Create a Hello World application using DataTable Grid.
- How to reuse common layouts in Angular using Router
- Angular 9 Routing Tutorial – Sending & Getting Routes Parameters
- Angular 9 Router Tutorial – Configure Routing & Navigation
- Handle CORS in Angular 8/9 with Proxy Configuration
- Error Handling in Angular 8/9 Tutorial with Examples
- Angular 8/9 SEO – Set Dynamic Page Title and Meta Tags in Universal App
- Handle Angular 9 HTTP Requests with Observables
- Angular 9/8 JWT User Authentication Tutorial
- Angular 8|9 File Upload with Progress Bar Tutorial
- Angular 8|9 Show Image Preview with Reactive Forms Tutorial
- Angular 8|9 NgFor Directive Tutorial with Examples
- TypeScript Promises Examples
- Angular 8|9 Custom Validation Tutorial with Examples
- Angular 8/9 Radio Buttons Tutorial with Examples
- Angular 8/9 Select Dropdown Tutorial with Reactive Forms
- Angular 8/9 HttpClient & Http Tutorial – Build, Consume RESTful API
- Angular 8/9 Reactive Forms Validation with Angular Material 8
- Angular 9/8 Location Service Tutorial with Example
- Creating Custom Directives in Angular 9/8
- Angular 9/8/7 ViewChild Tutorial – Access Child Component
- Angular 9/8/7 @Input Decorator Tutorial with Example
- Angular 9/8/7 NgIf, Else, Then – Work Like a Pro
- Useful List of Angular 7 Event Types for Event Binding
- Angular 8/9 Pipes Examples | Create Custom Angular Pipe
- Angular 7|8|9 Directives – Component, Structural & Attribute Directives
- Angular 7|8|9 Data Binding Tutorial
- Nested Routes
- Defining Child Routes
- Angular 7 CRUD Example (Full Stack App)
- https://github.com/sonuammy
- Bootstrap Spinners
- grokonez.com/angular-tutorial
Arrow functions are introduced in ES6, which provides you a more accurate way to write the functions in JavaScript. Arrow functions make your code more readable and structured.
Arrow functions are anonymous functions (the functions without a name and not bound with an identifier). They don't return any value and can declare without the function keyword. Arrow functions cannot be used as the constructors. The context within the arrow functions is lexically or statically defined. They are also called as Lambda Functions in different languages.
Arrow functions do not include any prototype property, and they cannot be used with the new keyword.
Before Arrow:
hello = function() {
return "Hello World!";
}
With Arrow Function:
hello = () => {
return "Hello World!";
}
Arrow Functions Return Value by Default:
hello = () => "Hello World!";
Arrow Function With Parameters:
hello = (val) => "Hello " + val;
In fact, if you have only one parameter, you can skip the parentheses as well:
hello = val => "Hello " + val;
function add(num1, num2){
return num1+num2;
}
function subtract(num1, num2){
return num1-num2;
}
function multiply(num1, num2){
return num1*num2;
}
function division(num1, num2){
return num1/num2;
}
function mod(num1, num2){
return num1%num2;
}
function power(num1, num2){
return num1**num2;
}
function calculate(num1, num2, callback){
return callback(num1, num2);
}
console.log(calculate(2,4, power));
Output: 16
Area = π × radius x radius
function areaOfCircle(radius) {
return Math.PI * radius ** 2;
}
console.log(areaOfCircle(5));
Output: 78.53981633974483
Area = side x side
function areaOfSquare(side) {
return side ** 2;
}
console.log(areaOfSquare(5));
Output: 25
To calculate the area of a triangle, you can use Heron's formula, given the lengths of its three sides, denoted as 𝑎, 𝑏, and 𝑐 where s is the semi-perimeter of the triangle:
s = (a + b + c) / 2 ;
Area = sqrt (s × (s−a) × (s−b) × (s−c) );
function areaOfTriangle(a, b, c) {
// Calculate the semi-perimeter
const s = (a + b + c) / 2;
// Calculate the area using Heron's formula
const area = Math.sqrt(s * (s - a) * (s - b) * (s - c));
return area;
}
const sideA = 3;
const sideB = 4;
const sideC = 5;
console.log(areaOfTriangle(sideA, sideB, sideC));
Output: 6
To convert Celsius to Fahrenhei:
Fahrenheit = (Celsius × 5/9) + 32
function celsiusToFahrenheit(celsius) {
return (celsius * 9 / 5) + 32;
}
const celsiusTemperature = 38;
const fahrenheitTemperature = celsiusToFahrenheit(celsiusTemperature);
console.log(celsiusTemperature + "°C is equal to " + fahrenheitTemperature + "°F");
Output: "38°C is equal to 100.4°F"
function isLeapYear(year) {
// Leap years are evenly divisible by 4
// Unless they are also divisible by 100, but not 400
return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
}
console.log(isLeapYear(2024));
Output: true
function evenOdd(num){
if(num===0){
return "It's Zero."
}
else if(num!==0 && num % 2 === 0 ){
return `${num} is Even No.`;
}
else{
return `${num} is Odd No.`;
}
}
console.log(evenOdd(4));
let a = 10;
let b = 20;
let temp = a;
a = b;
b = temp;
console.log("a : " +a);
console.log("b : " +b);
Output: "a : 20"
"b : 10"
Without third variable:
let a = 10;
let b = 20;
a = a + b;
b = a - b;
a = a - b;
console.log("a : " +a);
console.log("b : " +b);
Output: "a : 20"
"b : 10"
Using destructuring assignment:
let a = 10;
let b = 20;
[a, b] = [b, a];
console.log("a : " +a);
console.log("b : " +b);
Output: "a : 20"
"b : 10"
function randomNumber(min, max) {
const random = Math.random();
const scaled = random * (max - min) + min;
return parseInt(scaled);
}
console.log(randomNumber(1,5));
function factorialOf(num){
let result = 1;
while(num >= 1){
result = result * num;
num--;
}
return result;
}
console.log(factorialOf(6));
Output: 720
Recursive way:
function factorialOf(n) {
if (n === 0 || n === 1) {
return 1;
}
return n * factorialOf(n - 1);
}
console.log(factorialOf(6));
Output: 720
function fibonacciSeries(length) {
const series = [0, 1];
// Initialize the series with the first two Fibonacci numbers
// Generate subsequent Fibonacci numbers and add them to the series
for (let i = 2; i < length; i++) {
series.push(series[i - 1] + series[i - 2]);
}
return series;
}
console.log(fibonacciSeries(5));
Output: [0, 1, 1, 2, 3]
With recursion :
function fibonacci(n) {
if (n <= 1) {
return n;
} else {
return fibonacci(n - 1) + fibonacci(n - 2);
}
}
function fibonacciSeries(length) {
const series = [];
for (let i = 0; i < length; i++) {
series.push(fibonacci(i));
}
return series;
}
console.log(fibonacciSeries(5));
function isPrimeNumber(num) {
// Check if the number is less than 2 (not a prime number)
if (num < 2) {
return false;
}
// Iterate from 2 to half of the number
for (let i = 2; i <= num / 2; i++) {
// If the number is divisible by any integer between 2 and half of itself, it's not prime
if (num % i === 0) {
return false;
}
}
// If the number is not divisible by any integer between 2 and half of itself, it's prime
return true;
}
console.log(isPrimeNumber(18));
Output: true
function isPrime(number) {
if (number < 2) {
return false;
}
for (let i = 2; i <= Math.sqrt(number); i++) {
if (number % i === 0) {
return false;
}
}
return true;
}
console.log(isPrimeNumber(18));
Output: true
Prime numbers between 1 to n:
function isPrime(number) {
if (number < 2) {
return false;
}
for (let i = 2; i <= Math.sqrt(number); i++) {
if (number % i === 0) {
return false;
}
}
return true;
}
function findPrimesInRange(n) {
const primes = [];
for (let i = 2; i <= n; i++) {
if (isPrime(i)) {
primes.push(i);
}
}
return primes;
}
console.log(findPrimesInRange(50));
Output: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
function isPalindrome(num) {
const originalString = num.toString();
const reversedString = originalString.split('').reverse().join('');
return originalString === reversedString;
}
console.log(isPalindrome(12321));
Outout: true
An Armstrong number (also known as narcissistic number, plenary number, or plus perfect number) is a number that is equal to the sum of its own digits each raised to the power of the number of digits. For example, 153 is an Armstrong number because
1**3 + 5**3 + 3**3 = 1 + 125 + 27 = 153
function isArmstrongNumber(num) {
const numString = num.toString();
const numDigits = numString.length;
let sum = 0;
for (let digit of numString) {
sum += Math.pow(parseInt(digit), numDigits);
}
return sum === num;
}
console.log( isArmstrongNumber(153));
Output: true
A strong number (also known as a factorial sum number or Krishnamurthy number) is a number whose sum of the factorial of its digits is equal to the number itself. For example, 145 is a strong number because
1! + 4! + 5! = 1 + 24 + 120 = 145
function factorial(number) {
if (number === 0 || number === 1) {
return 1;
} else {
return number * factorial(number - 1);
}
}
function isStrongNumber(number) {
const numString = number.toString();
let sum = 0;
for (let digit of numString) {
sum += factorial(parseInt(digit));
}
return sum === number;
}
console.log(isStrongNumber(145));
Output: true
A Spy Number is a number where the sum of its digits equals the product of its digits. In other words, if we multiply all the digits of the number and add them, the result is the same as the number itself.
ex: 1, 2, 3, 4, 5, 6, 7, 8, 9, 22, 123, 132, 213, 231, 312, 321, 1124, 1142, 1214, 1241, 1412, 1421, 2114, 2141, 2411, 4112, 4121, 4211....
function isSpyNumber(num) {
const digits = num.toString().split('').map(Number);
const sum = digits.reduce((acc, curr) => acc + curr, 0);
const product = digits.reduce((acc, curr) => acc * curr, 1);
return sum === product;
}
console.log(isSpyNumber(1124));
function reverseNumber(number) {
const reversedString = number.toString().split('').reverse().join('');
return parseInt(reversedString, 10);
}
console.log(reverseNumber(123));
Output: 321
function conuntDigitInNumber(number) {
return number.toString().split('').length;
}
console.log(conuntDigitInNumber(54));
Output : 2
function sumOfDigits(number) {
let sum = 0;
const digits = number.toString().split('');
digits.forEach((el)=> {
sum = sum + parseInt(el, 10);
})
return sum;
}
console.log(sumOfDigits(54));
Output : 9
const arr = [3,6,2,1,8,6];
function sumOfArray(arr){
return arr.reduce((acc,curr) => acc + curr, 0)
}
console.log(sumOfArray(arr));
Output : 13
const sumOfArray = (arr) => arr.reduce((acc,curr) => acc + curr, 0);
console.log(sumOfArray(arr));
Output : 13
const sumOfArray = arr => arr.reduce((acc,curr) => acc + curr, 0);
console.log(sumOfArray(arr));
Output : 13
let sumOfArray = 0;
arr.forEach((el)=> sumOfArray = sumOfArray + el);
console.log(sumOfArray);
Output : 13
let array = [1, 2, 3, 4, 5];
console.log(array.reverse());
Output : [5, 4, 3, 2, 1]
let numbers = [10, 5, 8, 22, 18];
let maxNumber = Math.max(...numbers);
console.log(maxNumber);
Output: 22
let maxNumber = numbers.reduce((max, current) => (current > max ? current : max), numbers[0]);
let maxNumber = numbers[0];
numbers.forEach(number => {
if (number > maxNumber) {
maxNumber = number;
}
});
console.log(maxNumber);
let numbers = [10, 5, 8, 22, 18];
const sortedNumber = numbers.sort((a,b)=> b-a)
console.log(sortedNumber[1]);
Output: 18
let numbers = [1, 2, 3, 4, 4, 5, 6, 6, 7];
let uniqueNumbers = [...new Set(numbers)];
console.log(uniqueNumbers);
``
```ts
let numbers = [1, 2, 3, 4, 4, 5, 6, 6, 7];
let uniqueNumbers = numbers.filter((value, index, self) => self.indexOf(value) === index);
console.log(uniqueNumbers);
Output: [1, 2, 3, 4, 5, 6, 7]
let numbers = [1, 2, 3, 4, 4, 5, 6, 6, 7];
let uniqueNumbers = numbers.reduce((acc, value) => {
if (!acc.includes(value)) {
acc.push(value);
}
return acc;
}, []);
console.log(uniqueNumbers);
Output: [1, 2, 3, 4, 5, 6, 7]
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let oddNumbers = [];
let evenNumbers = [];
numbers.forEach(number => {
if (number % 2 === 0) {
evenNumbers.push(number);
} else {
oddNumbers.push(number);
}
});
console.log("Odd Numbers:", oddNumbers);
console.log("Even Numbers:", evenNumbers);
Output: Odd Numbers: [1, 3, 5, 7, 9]
Output: Even Numbers: [2, 4, 6, 8, 10]
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let oddNumbers = numbers.filter(number => number % 2 !== 0);
let evenNumbers = numbers.filter(number => number % 2 === 0);
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let { oddNumbers, evenNumbers } = numbers.reduce((acc, number) => {
if (number % 2 === 0) {
acc.evenNumbers.push(number);
} else {
acc.oddNumbers.push(number);
}
return acc;
}, { oddNumbers: [], evenNumbers: [] });
function addMatrices(matrixA, matrixB) {
// Ensure matrices have the same dimensions
if (matrixA.length !== matrixB.length || matrixA[0].length !== matrixB[0].length) {
throw new Error('Matrices must have the same dimensions to be added.');
}
// Initialize the result matrix
let resultMatrix = [];
for (let i = 0; i < matrixA.length; i++) {
resultMatrix[i] = [];
for (let j = 0; j < matrixA[i].length; j++) {
// Add corresponding elements
resultMatrix[i][j] = matrixA[i][j] + matrixB[i][j];
}
}
return resultMatrix;
}
// Example usage
let matrixA = [
[1, 2, 3],
[4, 5, 6]
];
let matrixB = [
[7, 8, 9],
[10, 11, 12]
];
let result = addMatrices(matrixA, matrixB);
console.log(result);
// Output:
// [
// [8, 10, 12],
// [14, 16, 18]
// ]
function multiplyMatrices(matrixA, matrixB) {
// Check dimensions
if (matrixA[0].length !== matrixB.length) {
throw new Error('Matrices cannot be multiplied: columns of matrix A must be equal to rows of matrix B.');
}
let resultMatrix = [];
for (let i = 0; i < matrixA.length; i++) {
resultMatrix[i] = [];
for (let j = 0; j < matrixB[0].length; j++) {
let sum = 0;
for (let k = 0; k < matrixA[0].length; k++) {
sum += matrixA[i][k] * matrixB[k][j];
}
resultMatrix[i][j] = sum;
}
}
return resultMatrix;
}
// Example usage
let matrixA = [
[1, 2, 3],
[4, 5, 6]
];
let matrixB = [
[7, 8],
[9, 10],
[11, 12]
];
let result = multiplyMatrices(matrixA, matrixB);
console.log(result);
// Output:
// [
// [58, 64],
// [139, 154]
// ]
function transposeMatrix(matrix) {
let transposedMatrix = [];
for (let i = 0; i < matrix[0].length; i++) {
transposedMatrix[i] = [];
for (let j = 0; j < matrix.length; j++) {
transposedMatrix[i][j] = matrix[j][i];
}
}
return transposedMatrix;
}
// Example usage
let matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
let transposed = transposeMatrix(matrix);
console.log(transposed);
// Output:
// [
// [1, 4, 7],
// [2, 5, 8],
// [3, 6, 9]
// ]
The expected sum of numbers from 1 to 100 can be calculated using the formula for the sum of an arithmetic series:
n×(n+1) / 2 , where n is the last number in the series (in this case, 100).
function findMissingNumber(arr) {
// Calculate the sum of numbers from 1 to 100
let expectedSum = (100 * 101) / 2; // Sum of an arithmetic series formula: n*(n+1)/2
// Calculate the sum of numbers in the array
let actualSum = arr.reduce((sum, num) => sum + num, 0);
// Find the missing number
let missingNumber = expectedSum - actualSum;
return missingNumber;
}
// Example usage
let numbersArray = [1, 2, 3, /*...*/, 99, 100]; // Array containing numbers from 1 to 100 with one missing number
let missingNumber = findMissingNumber(numbersArray);
console.log("Missing number:", missingNumber);
console.log(typeof "str");
Output: "string"
const str = "I am Sonu Kumar"
const result = str.split(" ").reverse().join(" ");
console.log(result);
Output: "Kumar Sonu am I"
function isPalindrome(str) {
let reversedStr = str.toLowerCase().split('').reverse().join('');
return str === reversedStr;
}
console.log(isPalindrome('aba'));
function removeDuplicates(str) {
let result = '';
for (let char of str) {
if (!result.includes(char)) {
result += char;
}
}
return result;
}
// Example usage
let inputString = "hello world";
let stringWithoutDuplicates = removeDuplicates(inputString);
console.log(stringWithoutDuplicates); // Output: "helo wrd"
function areAnagrams(str1, str2) {
// Remove non-alphanumeric characters and convert to lowercase
str1 = str1.replace(/[^a-z0-9]/g, '').toLowerCase();
str2 = str2.replace(/[^a-z0-9]/g, '').toLowerCase();
str1 = str1.split('').sort().join('');
str2 = str2.split('').sort().join('');
return str1 === str2;
}
console.log(areAnagrams("listen", "silent")); // Output: true
console.log(areAnagrams("hello", "world")); // Output: false
function findDuplicates(str) {
let duplicates = [];
for (let i = 0; i < str.length; i++) {
let char = str[i];
if (str.indexOf(char) !== i && !duplicates.includes(char)) {
duplicates.push(char);
}
}
return duplicates;
}
// Example usage
let inputString = "hello world";
let duplicateChars = findDuplicates(inputString);
console.log("Duplicate characters:", duplicateChars); // Output: ["l", "o"]