Skip to main content

Posts

Javascript interview questions set 3

  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

  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

Coding Interview questions set 6

Let's begin with set 6, 13)Given an array of integer nums and an integer target, return indices of the two numbers such that they add up to the target. Assumptions:  Each input would have exactly one solution, and you may not use the same element twice. Example 1: Input: nums = [2,7,11,15], target = 9 Output: [0,1] Output: Because nums[0] + nums[1] == 9, we return [0, 1]. Example 2: Input: nums = [3,2,4], target = 6 Output: [1,2] Solution: const twoSum = (nums, target) => {   const map = {};   for (let i = 0; i < nums.length; i++) {     const another = target - nums[i];     if (another in map) {       return [map[another], i];     }     map[nums[i]] = i;   }   return null; }; You may also like these articles:   Coding Interview Set 1     Coding Interview Set 2 .     Coding Interview Set 3   Coding Interview Set 4 14)Given an array of numbers containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Could you impleme

Node.js: create an excel file with multiple tabs.

This article is a sample code to generate an excel file with multiple tabs using  excel4node  module. Install: npm i excel4node Let's see the sample code, var excel = require( 'excel4node' ); // Create a new instance of a Workbook class var workbook = new excel.Workbook(); // Add Worksheets to the workbook var worksheet = workbook.addWorksheet( 'Buy order types' ); var worksheet1 = workbook.addWorksheet( 'Sell order types' ); // Style for headers var style = workbook.createStyle({ font : { color : '#EA3A14' , size : 18 }, numberFormat : '$#,##0.00; ($#,##0.00); -' }); var styleForData = workbook.createStyle({ font : { color : '#47180E' , size : 12 }, alignment : { wrapText : true , horizontal : 'center' , }, numberFormat : '$#,##0.00; ($#,##0.00); -' }); let buyOrderTypes = [ {name : "buy" ,id : "1" ,comment : "Normal

Coding Interview Questions set 5

  Let's begin with set 5, Q11)Valid Parentheses problem. 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=[];            for(let i=0;i<s.length;i++){        if(s[i] in obj) {           if(!stack.length || stack[stack.length-1]!==obj[s[i]]) {               return false;            }           else stack.pop();      }else stack.push(s[i]);   }  return !stack.length; }; L

Data structure problem 1:Implement a queue using 2 stacks.

This is one of the interview questions asked in technical or data structure round. As we know stack is first in last out and queue is first in first out. Here we have to implement the behaviour of queue using 2 stacks. So let's begin with one of the approaches, For 2 stacks we have define 2 arrays; var stack1=[]; var stack2=[]; For insertion or push, we will use stack1. For any insertion, we can push it in stack1 array. a)Insert "A" stack1.push("A"); b)Insert "B" stack1.push("B"); c)Insert "C" stack1.push("C"); Now when we remove or pop, the first pushed element should be removed first i.e behaviour of a queue.    So if we poped from stack1 we will get the behaviour of stack here. stack1.pop()//"C" will be removed i.e behaviour of stack last in first out. We can't use this, so we will need stack2 for this purpose to implement the behaviour of the queue. d)Remove or pop: For first remove or pop, we will need

javascript snippets interview questions set 3

  For the previous set please refer to  javascript snippets questions set 2. Let's  begin with set 3, Q12)After the following code, what is the value of a.length? var a = ['dog', 'cat', 'hen']; a[100] = 'fox'; a) 101 b) 3 c) 4 d) 100 Q13)What is the value of dessert.type after executing this code? const dessert = { type: 'pie' }; dessert.type = 'pudding'; a) pie b) The code will throw an error. c) pudding d) undefined Q14)Why would you include a "use strict" statement in a JavaScript file? a) to tell parsers to interpret your JavaScript syntax loosely b) to tell parsers to enforce all JavaScript syntax rules when processing your code c) to instruct the browser to automatically fix any errors it finds in the code d) to enable ES6 features in your code Q15)Which variable is an implicit parameter for every function in JavaScript? a) Arguments b) args c) argsArray d) argumentsList I hope you like the article. Please stay connect