Today's Question:  What does your personal desk look like?        GIVE A SHOUT

SEARCH KEYWORD -- Array



  Empty slice vs nil slice in GoLang

In Go, there is a type called slice which is built on top of array. It's a very convenient type when we want to handle a group of data. This post will explain a subtle but tricky difference between empty slice and nil slice. A nil slice is a slice has a length and capacity of zero and has no underlying array. The zero value of slice is nil. If a slice is declared like below, it is a nil slice. package main import "fmt" func main() { var a []string fmt.Println(a == nil) } The output will be t...

   GOLANG,JSON,EMPTY SLICE,NIL SLICE     2018-10-18 09:25:21

  Hash Tables in Javascript

IntroductionHash tables are a permutation of associative arrays (i.e. name => value pairs). If you use PHP, then you are very familiar with this type of data structure already since all PHP arrays are associative.The Javascript language implements very loose and somewhat limited support for associative arrays. Any JavaScript array can use other objects as keys, making it a hash, but there exists no formal constructor for initializing them and it is more or less unweildy to work with. A short ...

   JavaScript,Hashtable,Implementation,Array     2011-11-26 02:43:40

  Comparable and comparator in Java

Comparable and comparator are two similar interfaces used to compare objects in Java. When we want to sort a list of objects such as Employee or User etc, we may need to implement these interfaces to make them comparable as we want. However, there are some differences between comparable and comparator interface.ComparableA comparable object is capable of comparing itself with another object. The class itself must implements the java.lang.Comparable interface in order to be able to compare its in...

   Java,Comparable,Comparator,Sort     2012-07-04 12:06:15

  Find max subarray of an array

In computer science, the maximum subarray problem is the task of finding the contiguous subarray within a one-dimensional array of numbers (containing at least one positive number) which has the largest sum. For example, for the sequence of values −2, 1, −3, 4, −1, 2, 1, −5, 4; the contiguous subarray with the largest sum is 4, −1, 2, 1, with sum 6. The problem was first posed by Ulf Grenander of Brown University in 1977,...

   Max Subarray, Divide and conquer,Kadane     2013-04-22 11:50:35

  JavaScript-style object literals in PHP

The object literal notation in JavaScript looks like: var fido = {name: "Fido", barks: true}; or var fido = {}; fido.name = "Fido"; fido.barks = true; From assoc arrays to objects In PHP you would call that an associative array. $fido = array( 'name' => "Fido", 'barks' => true ); And you can easily make it an object too: $fido = (object)$fido; echo gettype($fido); // "object" Or if you want to start with a blank object and add stuff to it: $fido = (object)array(); or $fido...

   PHP,JavaScript,Object,Function call,Self vs this     2011-11-30 11:11:45

  Tips to improve JavaScript efficiency

Writing JavaScript code is tedious and error prone. You not only need to implement the necessary functions, but also need to ensure cross browser compatibility. This often causes the low efficiency of JavaScript developers. Here we recommend 12 tips you can benefit from. 1. Remove array element by index If we want to remove one element in an array, we can use splice. function removeByIndex(arr, index) { arr.splice(index, 1); } test = new Array(); test[0] = ’Apple’; test[1] = &rsq...

   JavaScript,Tips,Array     2013-07-27 20:50:40

  What does super.clone() do?

Object class has a protected clone() method declared to make it possible for all classes make a clone of itself when needed. The clone() is often used when a new instance of the class is needed while at the same time to maintain the same state as the original object. Any class which wants to have clone enabled has to implement the marker interface Cloneable. If a class which implements Cloneable doesn't override the Object.clone() method, the Object.clone() method will be called to just make a b...

   Cloneable,super.clone(),clone,Java     2015-01-07 05:25:52

  What does session_destroy() do in PHP?

In PHP manual, the description for session_destroy() function is : session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called. I am confused about this description. If this function destroys all session data, then why the global variables associated with the session are not unset? Why can we u...

   session_destroy,session_start     2013-08-31 09:59:05

  Why using + to concatenate string in Java loop is not a good option

String concatenation is a common operation in Java programming. It is to concatenate multiple strings into a single string. Java provides a String class which is an immutable class which means the object cannot be mutated once instantiated. Once a String object is instantiated, its properties cannot be changed anymore, so when concatenating strings, it's actually create a new String instance to store the concatenated string values. For example, below is a simple string concatenation example. Str...

   JAVA,STRING,JAVA 8     2019-01-18 22:07:12

  Undefined property or variable in JavaScript

JavaScript is a weak type language, and also you can use a variable or property where it's undefined. If we don't have correct ways to check whether a property or variable is defined, we may get unexpected results when we try to access the,. How can we check whether a property or variable is undefined? This is actually a somewhat tricky question. Let's start off with some facts about undefined and then see what kind of function is consistent with the ones we care about. JavaScript attaches type...

   Property,Undefined,Array,JavaScript     2014-07-24 06:56:07