Saturday 18 August 2018

Top Java Script Interview Questions and Answers with Examples 2018



1) What is Pure Function?

A pure function is a function

  • which accepts the same input and returns the same output.
  • It will not produce any side effects.
Example 1:


Example 2:

    Math.max( ) is predefined pure function in java script.
    It will accepts number of arguments and return the largest argument value.


2) What is Function Composition?

         Function composition is the process of combining two or more functions to produce a new function.

Example:
In the above example split( ), map( ) and join( ) functions are used to produce a new function.
So, It is called as a Function Composition(Composable Function)

3) What is a Promise?

A promise is an object which can be returned synchronously from an asynchronous function. It has 3 states:
  • Resolved: resolve() will be called.
  • Rejected: reject() will be called.
  • Pending: not yet resolved or rejected.
Example:

4) What is functional programming?

         Functional programming is the process of developing a software by using pure functions
Functional programming is a declarative programming and application state flows through pure functions.
The main features of functional programming are,
  • It is a programming paradigm.
  • Style of coding like way of approaching a code.
  • It is safer and easy to debug the code.
  • It avoids the side effects with pure functions.
  • It have Higher order functions.
  • It avoids the mutability.
Example 1:

Example 2:

5) What are first-class functions?

      First class functions are just like other variables in JavaScript functions. It is an instance of the Object type and have properties and a link back to its constructor method. We can pass it as a parameter to another function.

Example:

6) What is Currying?

       Currying is the process of transforming a function with multiple arity into the same function with the less arity.

Example:

7) What is Functor?

         A functor is nothing but something that can be mapped over.

Example:
The resultant array we can call it as a functor.

8) What is hoisting?

         Hoisting is nothing but a variable can be used before variable declaration.

Example:
In the same way function hoisting is, calling a function before its declaration.

Example:

9) What is function expression?

          Function expression is also called as first-class function.

Example:

10) What is immediate invoking function?

          Anonymous functions are also called as immediate invoking function.

Example:

11) What will be the output of the following code snippet?


The output is 1. For explanation refer question 6.

12) What will be the output of the following code snippet?


The output is 1 and 2.

13) What is prototype?

          Prototype is an object. All java script objects inherit the properties and methods from a prototype.

Example:

14) What is the difference between map( ), filter( ) and reduce( )?

            map( ) function is used to transform the array values into an array of items.

Example:

filter( ) is used to select the items based on certain condition.

Example:

reducer( ) is used to reduce an array into a value.

Example:

15) What will be the output of the following code snippet?

                       console.log( true + true );

Solution:
 
        In JavaScript, when you are trying to make arithmetic operations(like addition, subtraction, multiplication). true is converted to 1 and false is converted to 0.

        So, the solution for above  code snippet is 2.




Tuesday 19 September 2017

Java Program to find largest digit in the given input and calculate the multiples of the largest digit with all individual digits to single digit

Question:

Program to find largest digit in the given input and calculate the multiples of the largest digit with all individual digits to single digit

Input: 123
Output: Result: 9

Program:

import java.io.*;

public class LetUsCodeinJava{
     public static void main(String[ ] args){
          String inpStr = "123";
          int res = 0, sum = 0;
          int maxDigit = Integer.parseInt(inpStr.charAt(0) + "");
          // to find max digit in the given string
          for(int i = 0; i < inpStr.length( ); i++){
               if(Integer.parseInt(inpStr.charAt(i) + "") > maxDigit){
                    maxDigit = Integer.parseInt(inpStr.charAt(i) + "");
               }
          }
          // multiples of the largest digit with all individual digits
          for(int i = 0; i < inpStr.length( ); i++){
               res += maxDigit * Integer.parseInt(inpStr.charAt(i) + "");
          }
          // sum of digits to single digit
          while(res > 0 || sum > 9){
               if(res == 0){
                     res = sum;
                     sum = 0;
               }
               sum += res % 10;
               res /= 10;
           }
           System.out.println("Result: "sum);
     }
}

Output:

Result: 9

Explanation:

We need to divide the program into 3 section
1. to find max digit in the given string.
2. multiples of the largest digit with all individual digits.
3. sum of resultant digits to single digit.

In the 1st section we will get the largest digit

maxDigit = 3:

In the 2nd section we need to multiply all the digits with maxDigit

so, 1 * 3 = 3, 2 * 3 = 6, 3 * 3 = 9

res = 3 + 6 + 9 = 18

In the 3rd section we are calculating the sum of digits into single digit

so, sum = 1 + 8 = 9

Hence, Result = 9.



Monday 18 September 2017

Java Program to remove special characters and print sum of the unique numerical characters in the given string


Question:

Program to remove special characters and print sum of print sum of the unique numerical characters in the given string

Input: 123%#$.257
Output: Sum: 18

Program:

import java.io.*;

public class LetUsCodeinC{
     public static void main(String[ ] args){
           String inpStr = "123%#$.257";
           //Removing special characters from the given string
           inpStr = inpStr.replaceAll("[^0-9]","");
           String resStr = "";
           int sum = 0;
           //Removing duplicates from the resStr String
           for(int i = 0; inpStr.length( ); i++){
                if(!resStr.contains(String.valueOf(inpStr.charAt(i)))){
                     resStr += String.valueOf(inpStr.charAt(i));
                }
           }
           //Sum of all the numeric characters of resStr.
           for(int i = 0; resStr.length( ); i++){
                sum += Integer.parseInt(resStr.charAt(i) + "");
           }
           System.out.println("Sum: " + sum);
     }
}

Output:

Sum: 18

Explanation:

First we need to divide this program into 3 modules.
    1. Removing special characters from the given string.
    2. Removing duplicates from the resultant string.
    3. Sum of all the resultant numeric characters of string.




Java Program to remove duplicate characters in the given string


Question:

Program to remove duplicate characters in the given string
Input: 123346778
Output: 12345678

Program:

import java.io.*;

public class LetUsCodeinJava {
      public static void main(String[ ] args){
            String inpStr = "123346778";
            String resStr = "";
            for(int i = 0; i < inpStr.length( ); i++){
                 if(!resStr.contains(String.valueOf(inpStr.charAt(i)))){
                       resStr += String.valueOf(inpStr.charAt(i));
                 }
            }
            System.out.println(resStr);
      }
}

Output:

12345678



Java Program to remove special characters in the given String


Question:

Program to remove special characters in the given string
Input: 1746%$10.
Output: 174610

Program:

import java.io.*;
public class LetUsCodeinJava{
      public static void main(String[ ] args){
           String inpStr = "1746%$10.";
           inpStr = inpStr.replaceAll("[^0-9]","");
           System.out.println(inpStr);
      }
}

Output:

174610

Explanation:

In Java we have replaceAll( ) method to replace the sequence of matching characters with the matching regular expression and we can replace the string with whatever string.

  Syntax:-

  public String replaceAll(String regExpression, String repString)




Saturday 5 August 2017

Here is the trick to activate amazon prime membership for lifetime[100% Working]


amazon is the one of the leading and big online shopping website. Even if it is leading or big online shopping website, it may have some sort of loop holes or small hacks. Now I am going to explain one simple trick like how to activate amazon prime account for free. Just follow the below simple steps.

Step 1: Login to your amazon account.

Step 2: Now navigate to the amazon prime membership tab, as you can see in the below screenshot.


Step 3: Now click on the Join Prime, after that you will navigate to the following amazon prime webpage.

Step 4: Now click on the Join Prime today, after that you will navigate to the payment webpage.

Step 5: Here you go, Now select Net Banking as a payment method and HDFC/AXIS/ICICI


Step 6: Now click on the Continue without any doubt, after that you will navigate to billing address webpage.

Step 7: Now select respective  address or add a new address.

Step 8: Now you will be in Review your order page. Click on Place Your Order and Pay.

Step 9: Now you will navigate to the respective selected Bank Website.

Step 10: Now close the current page and open amazon website and check. 


That's it. Now you are an amazon prime user.

Enjoy unlimited fast delivery, Instant video streaming and earl access for exclusive deals.

Note:
This trick only work till 24hrs. After that again follow the same procedure.


See more:





Thursday 27 July 2017

Here is an awesome trick to use WhatsApp as a Search Engine[100% Working]

            Here is an amazing WhatsApp trick to access Wikipedia in the WhatsApp, Just follow the below steps to access Wikipedia in your WhatsApp.
Step 1: Save anyone of these numbers +919043017568 or +918015776749 as Wikipedia or Wiki in your mobile contact list.

Step 2: Now, Create a WhatsApp group and name it as Wikipedia or whatever your familiar name like My Notes, Search Engine, WhatsApp Bot... etc.

Step 3: After successfully creating the group, add those contact in this group as a participant.
WhatsApp Group(My Notes) -> Add participant


Step 4: Here you go, Now type queries and it will give the information in the fraction of seconds.

Example 1: just type Weather Bangalore

It will give the latest weather forecasting data as you can see in the below picture.



Example 2: Wiki India

It will give the brief information about India.


Example 3: Train 12712

It will track the given train(12712) and give the current running train details.


You can use it as a search engine also. It will give instant result.

Note:

    This awesome service is not provided by WhatsApp. It is provided by the group messenger Duta. for more information you can visit duta.in




Saturday 17 June 2017

Syntel Off Campus Recruitment Drive for Freshers


Company Overview:

Syntel is one the U.S based multinational company. It is a leading global provider of integrated technology and business services.

Headquarters Troy, Michigan, USA.
CEO & President Rakesh Khanna
Chairman & Co-Founder Bharat Desai
Co-Chairman Prashant Ranade.
Employees >22,000
Revenues >$966.6 million(aprox.)


Job Description:

Min. Pre-requisites:

B.Tech/B.E/MCA/MSC/BSC/BCA/BCS/Diploma/B.Com 2016 Graduates

Graduates:

B.Tech/B.E - Computer Science / Information Technology

MCA - Computers/Information Technology.

MSC - Computer Science/In Technology/Statistics/Mathematics.

Diploma - Computer Science/Information Technology

B.Com - Information Technology

Percentage:  Min. 60% in Xth, XIIth, Graduation  and Post-Graduation.

Job Location: Chennai/Mumbai/Pune

Note:
Candidate should not have any backlogs and maximum of 1 year break in entire education.




Apply Now: Registration Form




Wednesday 31 May 2017

Essential PH-1 Smartphone Specifications


Andy Rubin is one of the creators of the Android software. Recently he has launched his own smartphone called "Essential".

In 2014, Andy Rubin created a technology investment company named as Playground. Essential is one of the companies it funds and Essential Smartphone is their first product.


Essential PH-1 Specifications

Network GSM - Band (2 / 3 / 5 / 8); WCDMA - Band (1 / 2 / 5 /8); LTE (FDD) - Band (1 / 3 / 5 / 7 / 8 / 20)
Announced May, 2017
Dimensions 141.5 x 71.1 x 7.8 mm (5.57 x 2.80 x 0.31 in)
Weight 185 g (6.53 oz)
SIM Dual SIM (Nano-SIM, dual stand-by)
Display Type LTPS IPS LCD capacitive touchscreen, 16M colors, Corning Gorilla Glass 5
Display Size 5.71 inches
Operating System Android 7.1
Processor Type Qualcomm MSM8998 Snapdragon 835
Processor Core Octa Core
Processor Clock Speed 1.9GHz
Internal Storage 128 GB
RAM Memory 4 GB
Primary Camera Dual 13 MP, f/1.9, phase detection & laser autofocus, LED flash, touch focus, face detection, HDR, panorama
Secondary Camera 8 MP, f/2.2, 2160p@30fps, 1080p@60fps, 720p@120fps
3.5mm audio Jack No
GPS Yes, with A-GPS, GLONASS
Bluetooth 5.0, A2DP, EDR, LE
Radio No
Fingerprint Sensor Yes
Other Sensors accelerometer, gyro, proximity, compass, barometer
Battery Type Non-removable Li-Ion 3040 mAh battery

Tuesday 14 March 2017

Java Program on String Manipulations




Write a JAVA program to print following output?

Input Format:

tech prompt

Output Format:

TECH PROMPT
Tech Prompt

Program:

import java.io.*;
import java.lang.*;
public class Test{
   public static void main(String args[ ]){
      String inp = "tech prompt";
      String a[ ] = inp.split(" ");
      System.out.println(inp.toUpperCase( ));
      for(int i = 0;i <  a.length;i++){
            String str = a[i];
            System.out.print((str.substring(0,1).toUpperCase( ) + str.substring(1, str.length( )));
      }
   }
}