Posts

Rapid fire 28 javascript questions and answers .

Image
  Check these rapid javascript questions and answers that will help you to understand Javascript in a different way. Question 1: What is typeof [] ? Ans: Object. Actually, Array is derived from Object. If you want to check the array use Array.isArray(arr) Question 2: What is typeof arguments? Ans: Object. arguments are array-like but not array. it has length, can access by index but can't push pop, etc. Question 3: What is 2+true? Ans: 3. The plus operator between a number and a boolean or two boolean will convert boolean to number. Hence, true converts to 1 and you get a result of 2+1 Question 4: What is '6'+9 ? Ans: 69. If one of the operands of the plus (+) operator is a string it will convert other numbers or boolean to string and perform concatenation. For the same reason, "2"+true will return "2true" Question 5: What is the value of 4+3+2+"1" ? Ans: 91 . The addition starts from the left, 4+3 results 7 and 7+2 is 9. So far, the plus o

Mongodb Basics Set 1: Insert Operation

Image
  In this series, I would be sharing a few basic MongoDB articles on different operations. 1 )Insert a single record in MongoDB collection . var param = { firstname: "joey" , middlename: "" , lastname: "tribani" , phone: 9898989898 } db . collection( 'exampleset' ) . insertOne(param) This returns something like this: { "acknowledged" : true, "insertedId" : ObjectId( "56fc40f9d735c28df206d078" ) } You can also use 'insert' commond for inserting single record . db . collection( 'exampleset' ) . insert(param); This returns : WriteResult({ "nInserted" : 1 }); 2 )Insert multiple records in MongoDB collection . var records = [{ firstname: "joey" , middlename: "" , lastname: "tribani" , phone: 9898989898 },{firstname: "koey" , middlename: "" , lastname: "desuoiza" , phone: 9898989898

Coding interview questions set 7

Image
Let's begin with set 7, Q15) Best Time to Buy and Sell Stock You are given an array of prices where prices[i] is the price of a given stock on an ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0. Example 1: Input: prices = [7,1,5,3,6,4] Output: 5 Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5. Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell. Example 2: Input: prices = [7,6,4,3,1] Output: 0 Explanation: In this case, no transactions are done and the max profit = 0.   Solution: var maxProfit = function (prices) { var min = Number .MAX_SAFE_INTEGER; var max = 0 ; for ( var i = 0 ; i < prices.length; i ++ ) { min = Math .min(min, prices[i]); max =

Data structure problem 2 (Stack): Valid Parentheses problem.

Image
This is one of the interview questions asked in the technical or data structure round which can be solved using stack. As we know  stack is first in last out . You may also like this: Data structure problem 1.  So let's begin with the problem statement, Given a string s containing only the characters (, ), {, }, [ and ],  determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Examples : a)Input: s = "()" Output: true Example 2: b)Input: s = "()[]{}" Output: true Example 3: c)Input: s = "(]" Output: false Solution: var isValid = function (s) { const obj = { "}" : "{" , "]" : "[" , ")" : "(" , }, var stack = []; //As javascript array behaves like stack for ( let i = 0 ; i < s.length; i ++ ) { if (s[i

Create a multi column csv report in nodejs without external library.

Image
Recently I had a requirement to create a CSV report with multiple columns(merging two or more reports) in a single CSV file, but I didn't find any particular library(Maybe I didn't search properly) but found this solution.  So let's begin with code that is self-explanatory. const fs = require( 'fs' ); const _file = ` Agent_Customer_Report.csv ` //Report 1 const header1 = [ 'Customer Name' , 'DOB' , 'City' , 'Pincode' ]; const field1 = [ 'custName' , 'dob' , 'city' , 'pincode' ]; const report1Data = [{ 'custName' : "ABHISHEK" , 'dob' : '01/23/1992' , 'pincode' : '443221' , 'city' : "Mumbai" }{ 'custName' : "PUNIT" , 'dob' : '01/23/1992' , 'pincode' : '443221' , 'city' : "Mumbai" }] //Report2 const header2 = [ 'Agent Name' , 'DOB' , 'City

Javascript interview questions set 3

Image
  For set 2 please refer to the  Javascript interview question set 2. Let's begin with set 3, 5)Different Array methods? a)Array map() Method? .map() It is used when you want to transform elements in an array. The map() method creates a new array with the results of calling a function for every array element. The map() method calls the provided function once for each element in an array, in order. Note: this method does not change the original array. Ex:var numbers = [65, 44, 12, 4]; var newarray = numbers.map(myFunction) function myFunction(num) {   return num * 10; } b)When to use the filter method? .filter()  when you want to select a subset of multiple elements from an array. The filter() method creates an array filled with all array elements that pass a test (provided as a function). Note: filter() does not change the original array. Ex: var ages = [32, 33, 16, 40]; function checkAdult(age) {   return age >= 18; } ages.filter(checkAdult); c)When to use find()? .find() When

CSS INTERVIEW QUESTIONS SET 2

Image
  You make also like this CSS interview question set 1. Let's begin with set 2, 5)What is the difference between opacity 0 vs display none vs visibility hidden? Property           | occupies space | consumes clicks | +--------------------+----------------+-----------------+ | opacity: 0         |        yes      |        yes       | +--------------------+----------------+-----------------+ | visibility: hidden |        yes       |        no        | +--------------------+----------------+-----------------+ | display: none      |        no       |        no        | When we say it consumes click, that means it also consumes other pointer-events like onmousedown,onmousemove, etc. In essence "visibility: hidden" behaves like a combination of "opacity: 0" and "pointer-events: none". 6)CSS 3 new features? CSS3 allows developers to style HTML elements easier.  They are less dependent on image files  and can complete CSS styling with fewer lines of code. CSS3