Posts

Showing posts from May, 2023

AJS and Strings practice questions

Image
  1) Check whether a string is Palindrome or not  /** * Palindrome Check if the given string is a palindrome string. A sequence is said to be palindrome if reverse of the sequence is same as the initial sequence. Input Single line containing a string with no end of line character. String sequence contain only alphabets. Consider lower case letters as equivalent to upper case letters. Output Single containing YES if it is a palindrome Single containing NO if it isn't a palindrome Example Input: Tenet Output: YES */ let fs = require ( "fs" ); let data = fs . readFileSync ( 0 , "utf-8" ); let idx = 0 ; data = data. split ( " \n " ); function readLine () { idx ++ ; return data[idx - 1 ]. trim (); } // -------- Do NOT edit anything above this line ---------- // Use readLine() for taking input, it will read one line of from the input and is stored in string format let string = readLine (); let lenght = string. length ; let mark = true...

Introduction to Strings

Image
  1) .charCodeAt() method to find the ASCII number of all the letters, characters and numbers. 2) Logic to Understand & Revise  let currentLine = [ "is" , "hms" , "xy" ]; let spaces = 3 ; let j = 0 ; while (spaces) { if (j === currentLine.length - 1 ) { j = 0 ; continue ; } currentLine[j] += " " spaces -- ; j ++ ; } console. log (currentLine. map ( a => [ a , a . length ])); 3) 

Questions

Lecture 14

Lecture 13

Lecture 11 & 12

Scope and Closures / Callback Hell

Image
  1)  Scope: 1) Scope in JavaScript actually determines the accessibility of variables and functions at various parts in one’s own code or program. 2) Scope will help us to determine a given part of a code or a program, what variables or functions one could access and what variables or functions one cannot access. 3) Within a scope itself, a variable or a function, or a method could be accessed. Outside the specified scope of a variable or function, the data cannot be accessed. 4) There are three types of scopes available in JavaScript: Global Scope, Local / Function Scope, and Block Scope.  //global scope let global = "Swati" ; function func1 () { return global; } function func2 () { return func1 (); } console. log ( func2 ()); //local scope function func1 () { let a = 2 ; let multiply = function () { console. log (a * 5 ); } multiply (); } func1 (); //Block scope { let a = 5 ; } console. log (a); 2) Scope Nesting: //Bl...