Showing posts with label interview. Show all posts
Showing posts with label interview. Show all posts

Thursday, November 30, 2023

Pair check in Javascript

 

const arr = [1, 5, 2, 1, 6, 2, 2, 9];
const countPairs = (arr = []) => {
   const { length } = arr;
   let count = 0;
   // making a shallow copy so that the original array remains unaltered
   const copy = arr.slice();
   copy.sort((a, b) => a - b);
   for(let i = 0; i < length; i++){
      if(copy[i] === copy[i + 1]){
         i++;
         count++;
      };
   };
   return count;
};
console.log(countPairs(arr));

Wednesday, January 4, 2023

JavaScript Array cheat Sheet

 

JavaScript Array

NameDescription
concat()Joins arrays and returns an array with the joined arrays 
constructorReturns the function that created the Array object's prototype
copyWithin()Copies array elements within the array, to and from specified positions
entries()Returns a key/value pair Array Iteration Object 
every()Checks if every element in an array pass a test array.every(function(currentValue, index, arr), thisValue)
fill()Fill the elements in an array with a static value array.fill(value, start, end)
filter()Creates a new array with every element in an array that pass a test array.filter(function(currentValue, index, arr), thisValue)
find()Returns the value of the first element in an array that pass a test array.find(function(currentValue, index, arr),thisValue)
findIndex()Returns the index of the first element in an array that pass a test array.findIndex(function(currentValue, index, arr), thisValue)
forEach()Calls a function for each array element
from()Creates an array from an object
includes()Check if an array contains the specified element
indexOf()Search the array for an element and returns its position
isArray()Checks whether an object is an array
join()Joins all elements of an array into a string
keys()Returns a Array Iteration Object, containing the keys of the original array
lastIndexOf()Search the array for an element, starting at the end, and returns its position
lengthSets or returns the number of elements in an array
map()Creates a new array with the result of calling a function for each array element
pop()Removes the last element of an array, and returns that element
prototypeAllows you to add properties and methods to an Array object
push()Adds new elements to the end of an array, and returns the new length
reduce()Reduce the values of an array to a single value (going left-to-right)
reduceRight()Reduce the values of an array to a single value (going right-to-left)
reverse()Reverses the order of the elements in an array
shift()Removes the first element of an array, and returns that element
slice()Selects a part of an array, and returns the new array
some()Checks if any of the elements in an array pass a test
sort()Sorts the elements of an array
splice()Adds/Removes elements from an array
toString()Converts an array to a string, and returns the result
unshift()Adds new elements to the beginning of an array, and returns the new length
valueOf()Returns the primitive value of an array

Friday, April 8, 2022

React- UI Architect Interview Questions

Javascript
  1.  Difference between for each and map
  2. Pair check with String or array like 
    input = Hello and output should be {H:1, e:1, l:2, o:1}
    OR [10, 40, 20, 40, 30, 20, 40, 10] output in pair count 
  3. React performance 
  4. Prev props in function component 
  5. Render Props in react 
  6. Solid Principle 
======================
    Angular Architect Interview 
  1. How TO create Dynamic form in Angular 
  2. Micro frontEnd in Angular 
  3. Project estimation scenario Like if you have requirements under discussion and you need to give some timeline ,
  4. Project proposals 
  5. What All NFRS you should have for FE