Skip to main content

Posts

deloite

 1) x=10;   console.log(x); var x=0; output:10 2) WeakMap A WeakMap is a built-in JavaScript data structure introduced in ECMAScript 6 (ES6) that allows you to create a collection of key-value pairs where keys are objects and values can be arbitrary data. Unlike Map, keys in a WeakMap are weakly referenced, meaning they don't prevent their associated objects from being garbage collected when no other references to them exist. Here's a brief overview of WeakMap: Usage: WeakMap is used when you want to associate metadata or additional information with objects without preventing those objects from being garbage collected when they're no longer needed elsewhere in your code. Key Characteristics: Keys must be objects (primitive data types like numbers or strings are not allowed as keys). Values can be any type of data. Keys in a WeakMap are weakly referenced, meaning they don't prevent garbage collection of their associated objects. If an object used as a key in a WeakMa...

Lnt Mindtree part1

 1)Given an number N and an array of size N-1 containing N-1 numbers between 1 to N. Find the number(between 1 to N), that is not present in the given array. let N = 5; let Arr = [1, 2, 4, 5]  sum=n*(n+1)/2 for(let i=0;i<arr.length;i++){ sum-=arr[i] } console.log(sum) 2)Input: pattern = "abba", s = "dog cat cat dog " Output: true function wordPattern(pattern, s) {     const words = s.split(' ');     if (pattern.length !== words.length) {         return false;     }          const charToWord = new Map();          for (let i = 0; i < pattern.length; i++) {         const char = pattern[i];         const word = words[i];                  if (charToWord.has(char)) {             if (charToWord.get(char) !== word) {               ...

Globant part 3

 1)ES6 features: ES6 (ECMAScript 2015) introduced many new features and syntax improvements to JavaScript. Here are some notable ES6 features along with examples: 1. Arrow Functions: Arrow functions provide a more concise syntax for writing anonymous functions. javascript Copy code // ES5 function add(a, b) {   return a + b; } // ES6 const add = (a, b) => a + b; 2. Template Literals: Template literals allow embedding expressions inside strings using backticks (`). javascript Copy code // ES5 var message = "Hello, " + name + "!"; // ES6 let message = `Hello, ${name}!`; 3. Destructuring Assignment: Destructuring allows extracting values from objects or arrays and assigning them to variables. javascript Copy code // ES5 var person = { name: 'John', age: 30 }; var name = person.name; var age = person.age; // ES6 const { name, age } = { name: 'John', age: 30 }; 4. Spread Syntax: The spread syntax (...) allows expanding iterable objects (e.g., arrays) i...

Globlant part 2

 1)JWT token:           const jwt = require ( 'jsonwebtoken' ); A JWT token consists of three parts separated by dots ( . ): Header : Contains metadata about the type of token and the hashing algorithm used. Payload (Claims) : Contains the claims or statements about the subject of the token, such as user ID, roles, etc. Signature : Verifies that the sender of the JWT is who it says it is and ensures that the message wasn't changed along the way. It is header +payload +secret key. Methods: const newToken = jwt. sign (payload, secretKey, { expiresIn : '1h' }); Use verify() when you need to ensure the token's integrity and authenticity. Use decode() when you only need to extract information from the token and don't need to verify its signature. 2)Window ,this,global: In nodejs this and global refers to same global methods and varibales just that no dom related things that are in window. In nodejs no window. 3)a.getSum(); // Define the custom method getSu...