Skip to main content

Posts

Showing posts from June, 2023

Coding questions of latest interview

  //1)code to remove duplicates from array var array2 = [ 1 , 4 , 3 , 2 , 4 , 5 , 5 , 6 ]; for ( let i = 0 ; i < array2 . length ; i ++ ){ while ( array2 . includes ( array2 [ i ], i + 1 )){ var index = array2 . indexOf ( array2 [ i ], i + 1 ) array2 . splice ( index , 1 ) } } console . log ( array2 ) //2)write a code to flaten an array var array4 = [[ 1 , 2 , 3 ],[[ 1 , 6 , 7 ]]]; var output = []; function flaten ( array4 ){ for ( let item of array4 ){ if ( Array . isArray ( item )){ flaten ( item ) } else { output . push ( item ) } } } flaten ( array4 ); console . log ( output ) //3)Write a code to get sum of pairs from an array for an target var target = 10 ; var sumarray = [ 1 , 9 , 5 , 5 , 3 , 7 , 9 ]; var outputpairs = []; function findtarget ( sumarray , target ){ for ( let i = 0 ; i < sumarray . length ; i ++ ){ var diff = target - sumarray [ i ]; if ...

Interview questions angular and node

 1)Template ref vs element ref in angular: In a simplified way, the main difference between ElementRef and TemplateRef in Angular is as follows: ElementRef: Represents a reference to a specific element in the DOM (Document Object Model). Provides access to the native element, allowing you to manipulate its properties and invoke native DOM methods. It's useful when you need direct access to the underlying HTML element for tasks such as changing styles, manipulating attributes, or performing other DOM-related operations. TemplateRef: Represents a reference to an Angular template, which is a section of markup that can be instantiated. It doesn't provide direct access to the native element, but rather represents a reusable piece of UI structure that can be dynamically rendered in different parts of your application. It's useful when you want to define a template once and reuse it in multiple places, such as using ngTemplateOutlet or creating dynamic components with ViewContaine...