kamalraj's Profile

45
Points

Questions
0

Answers
22

  • Asked on February 5, 2019 in Android.

    Program

    1. //Program to count repeated words in string
      public class CountWords
      {

      public static void main(String[] args)
      {
      String input=“Welcome to Java Session Session Session”; //Input String
      String[] words=input.split(” “); //Split the word from String
      int wrc=1; //Variable for getting Repeated word count

      for(int i=0;i<words.length;i++) //Outer loop for Comparison
      {
      for(int j=i+1;j<words.length;j++) //Inner loop for Comparison
      {

      if(words[i].equals(words[j])) //Checking for both strings are equal
      {
      wrc=wrc+1; //if equal increment the count
      words[j]=“0”; //Replace repeated words by zero
      }
      }
      if(words[i]!=“0”)
      System.out.println(words[i]+“–“+wrc); //Printing the word along with count
      wrc=1;

      }

      }

      }

    • 780 views
    • 12 answers
    • 0 votes
  • Asked on February 5, 2019 in Javascript.

    There’s a rather large change coming to errors in Node.js: errors will have codes that follow a consistent and repeatable scheme.

    Previously, any kind of change to errors needed to be shipped in a semver major release. This became a major pain point, and is exemplified by something as trivial as wanting to correct a typo in an error, but needing to wait until the next major version of Node.js to ship.

    This has the added benefit of helping normalize errors across platforms, making for a more consistent development experience no matter the operating system being used.

    If you’d like to learn more about the new implementation of error codes in Node.js, be sure to check out Michael Dawson’s post about it here.

    • 926 views
    • 3 answers
    • 0 votes
  • Asked on February 5, 2019 in Javascript.

    This code sample shows the issue you can encounter when using this method:

    var arr1 = ['a','b','c','d','e','f'];
    var arr2 = arr1;  // Reference arr1 by another variable 
    arr1 = [];
    console.log(arr2); // Output ['a','b','c','d','e','f']
    • 469 views
    • 8 answers
    • 0 votes
  • Asked on February 5, 2019 in Javascript.

    For backward compatibility you can add the following

    # only implement if no native implementation is available
    if (typeof Array.isArray === 'undefined') {
      Array.isArray = function(obj) {
        return Object.prototype.toString.call(obj) === '[object Array]';
      }
    };

    If you use jQuery you can use jQuery.isArray(obj) or $.isArray(obj). If you use underscore you can use _.isArray(obj)

    If you don’t need to detect arrays created in different frames you can also just use instanceof

    obj instanceof Array
    • 576 views
    • 7 answers
    • 0 votes
  • Asked on February 5, 2019 in Javascript.

    That seems to be Chrome’s new way of displaying uninitialized indexes in arrays (and array-like objects):

    > Array(100)
    [undefined × 100]

    Which is certainly better than printing [undefined, undefined, undefined,...] or however it was before.

    Although, if there is only one undefined value, they could drop the x 1.

     

     

     

     

     

     

    • 503 views
    • 4 answers
    • 0 votes
  • Asked on February 5, 2019 in Javascript.

    Function Declaration

    function foo() { ... }

    Because of function hoisting, the function declared this way can be called both after and before the definition.

    Function Expression

    1. Named Function Expression
      var foo = function bar() { ... }
    2. Anonymous Function Expression
      var foo = function() { ... }

    foo() can be called only after creation.

    Immediately-Invoked Function Expression (IIFE)

    (function() { ... }());
    • 493 views
    • 7 answers
    • 0 votes
  • Asked on February 5, 2019 in Javascript.

    I am learning javascript hoisting and came across a scenario for which I need a bit more explanation. Below is the program that I have test(); console.log(“The value of data is “+data); function … console as undefined so I presume that the data variable is hoisted. Is variable hoisting only inside the function? In the above program, if the data is hoisted does that imply that the data variable …

    • 630 views
    • 8 answers
    • 0 votes
  • Asked on February 5, 2019 in Javascript.
    string="0123456789"                   # create a string of 10 characters
    array=(0 1 2 3 4 5 6 7 8 9)           # create an indexed array of 10 elements
    declare -A hash
    hash=([one]=1 [two]=2 [three]=3)      # create an associative array of 3 elements
    echo "string length is: ${#string}"   # length of string
    echo "array length is: ${#array[@]}"  # length of array using @ as the index
    echo "array length is: ${#array[*]}"  # length of array using * as the index
    echo "hash length is: ${#hash[@]}"    # length of array using @ as the index
    echo "hash length is: ${#hash[*]}"    # length of array using * as the index

    output:

    string length is: 10
    array length is: 10
    array length is: 10
    hash length is: 3
    hash length is: 3
    • 573 views
    • 5 answers
    • 0 votes
  • Asked on February 5, 2019 in Apache-spark.

    One website said : In Python 3.x the range() function returns a special range object which computes elements of the list on demand (lazy or deferred evaluation): >>> r = range(10) >>> print(r) range(0, 10) >>> print(r[3]) 3 What is meant by this? …

    • 833 views
    • 10 answers
    • 0 votes
  • from pyspark.sql.types import IntegerType from pyspark.sql.functions import udf, struct sum_cols = udf(lambda x: x[0]+x[1], IntegerType()) a=spark.createDataFrame([(101, 1, 16)], [‘ID’, ‘A’, ‘B’]) a.show() a.withColumn(‘Result’, sum_cols(struct(‘A’, ‘B’))).show()

    • 6927 views
    • 8 answers
    • 0 votes