If I map through an array using parseInt it returns unexpected and incorrect results:    console.log(["1234-04-23", "1234", "04", "23"].map(parseInt)) // =&gt; [1234, NaN, 0, 2]     but redundantly adding an arrow function wrapper works as expected    console.log(["1234-04-23", "1234", "04", "23"].map(e =&gt; parseInt(e))) // =&gt; [1234, 1234, 4, 23]     These two statements should behave identically, so why does the first one break?
1890
From the :  [1,4,9].map(Math.sqrt)   will yield:  [1,2,3]   Why then does this:  ['1','2','3'].map(parseInt)   yield this:  [1, NaN, NaN]   I have tested in Firefox 3.0.1 and Chrome 0.3 and just as a disclaimer, I know this is not cross-browser functionality (no IE).  I found out that the following will accomplish the desired effect. However, it still doesn’t explain the errant behavior of parseInt.  ['1','2','3'].map(function(i){return +i;}) // returns [1,2,3]
13369
I have an Object[] array, and I am trying to find the ones that are primitives. I've tried to use Class.isPrimitive(), but it seems I'm doing something wrong:  int i = 3; Object o = i;  System.out.println(o.getClass().getName() + ", " +                    o.getClass().isPrimitive());   prints java.lang.Integer, false.  Is there a right way or some alternative?
32327
All the documentation I've found so far is to update keys that are already created:  arr['key'] = val;  I have a string like this: &quot; name =  oscar &quot;  And I want to end up with something like this: { name: 'whatever' }  That is, split the string and get the first element, and then put that in a dictionary. Code var text = ' name = oscar ' var dict = new Array(); var keyValuePair = text.split(' = '); dict[ keyValuePair[0] ] = 'whatever'; alert( dict ); // Prints nothing.
40166
Is there a way to use constants in JavaScript?  If not, what's the common practice for specifying variables that are used as constants?
11190
When building console applications that take parameters, you can use the arguments passed to Main(string[] args).   In the past I've simply indexed/looped that array and done a few regular expressions to extract the values. However, when the commands get more complicated, the parsing can get pretty ugly.    So I'm interested in:   Libraries that you use Patterns that you use   Assume the commands always adhere to common standards such as .
12628
Is there a benefit to using one over the other? In Python 2, they both seem to return the same results:  &gt;&gt;&gt; 6/3 2 &gt;&gt;&gt; 6//3 2
107627
Is it the same convention as those used in known programming languages such as Java and C? I'm trying to create a lot of variables and I want it to start with a number, but I'm not sure if it's okay.
104870
I've been working on this task (see screenshot).     Here's my answer to it so far:  var sum_pairs=function(ints, s){   //your code here    var ptr_1 = 0,       ptr_2 = 0,       i = 0,       j = 0,       len = ints.length,       j_min = len,       arr_sum = [];    for (i; i &lt; len-1; i++){     for (j = i+1; j &lt; len; j++){       if(ints[i] + ints[j] === s){         if (j &lt; j_min){           j_min = j;           arr_sum = [parseInt(ints[i]), parseInt(ints[j])]         }       }     }   }  return ( (arr_sum.length === 0)? undefined : arr_sum );   }   However, while the tests all pass, it throws an STDERR about 'optimising the code':    How might I be able to optimise my code further?
69619
This is my first foray into the pgfkeys package and I found the following behavior really odd. The Tikz/pgfkeys manual mentions two ways for setting key values: \pgfkeys{key=value} and \pgfkeyssetvalue{key}{value}. When I tried both, they return different values. MWE:  \documentclass{article} \usepackage{tikz}  \pgfkeys{/my color/.initial = red, /my color/.estore in = \mycolor}  \begin{document}  \pgfkeys{/my color=blue} The colors are \mycolor{} and \pgfkeysvalueof{/my color}.  \pgfkeyssetvalue{/my color}{yellow} The colors are \mycolor{} and \pgfkeysvalueof{/my color}.  \end{document}   The output is:  The colors are blue and red. The colors are blue and yellow.   I was expecting all blue on the first line and all yellow on the second. What went wrong?
23909
Looking for reviewers to suggest optimization and improvements, and to evaluate coding practices.  final class Variables {     private final int x;     private final int y;      Variables(int x2, int y2) {         this.x = x2;         this.y = y2;     }      public int getX() {         return x;     }      public int getY() {         return y;     }      @Override public String toString()  {          return "x = " + x + " y = " + y;     } }  public final class FindMissing {      private FindMissing() {};      /**  * Takes an input a sorted array with two variables that repeat in the  * range. Remaining variable are consecutive. and returns two variables that repeats  *   * eg: for a range of 1,2,3,4, a valid input is [1, 4], [1, 3] etc.  *   * @param a : the sorted array.  */ /*  * Why is start needed ?  * If start is not given then if a1 is empty how do we know if missing numbers were  * [1, 2] or [4, 5] ??.   */ public static Variables sortedConsecutiveTwoMissing (int[] a, int startOfRange) {     if (a == null) throw new NullPointerException("a1 cannot be null. ");      int low = startOfRange;     // calculating the highest value of the range. it needs to be 2 more than length since all elememts are consecutive.     int high = startOfRange + (a.length - 1) + 2;      int i = 0;     boolean foundX = false;     int x = 0;       while (i &lt; a.length) {         if (a[i] != low) {             if (foundX) {                 return new Variables(x, low);             } else {                 x = low;                 foundX = true;             }         } else {             i++;         }         low++;     }      return new Variables(x, high);  }  public static void main(String[] args) {         // unsortedConsecutiveTwoMissing         int[] a6 = {1, 4};         System.out.println("Expected 2 and 3, Actual " + sortedConsecutiveTwoMissing(a6, 1));         // unsortedConsecutiveTwoMissing         int[] a7 = {-4, -1};         System.out.println("Expected -3 and -2, Actual " + sortedConsecutiveTwoMissing(a7, -4));         int[] a8 = {-4, -3, -2, -1};         System.out.println("Expected 0 and 1, Actual " + sortedConsecutiveTwoMissing(a8, -4));         int[] a9 = {5};         System.out.println("Expected 4 and 6, Actual " + sortedConsecutiveTwoMissing(a9, 4));         }      }
37844
Is there a good reason why there is no Pair&lt;L,R&gt; in Java? What would be the equivalent of this C++ construct? I would rather avoid reimplementing my own.  It seems that 1.6 is providing something similar (AbstractMap.SimpleEntry&lt;K,V&gt;), but this looks quite convoluted.
20930
I would like to filter an array of items by using the map() function. Here is a code snippet:  var filteredItems = items.map(function(item) {     if( ...some condition... )     {         return item;     } });   The problem is that filtered out items still uses space in the array and I would like to completely wipe them out.  Any idea?  EDIT: Thanks, I forgot about filter(), what I wanted is actually a filter() then a map().  EDIT2: Thanks for pointing that map() and filter() are not implemented in all browsers, although my specific code was not intended to run in a browser.
39889
This script:  a=2 [[ "$a" -eq 2 ]] &amp;&amp; echo yes1 [[  $a  -eq 2 ]] &amp;&amp; echo yes2 [[   a  -eq 2 ]] &amp;&amp; echo yes3 [[  "a" -eq 2 ]] &amp;&amp; echo yes4   Does not work in  (and some others that do not have [[ ). Fails the last two "yes tests" in  (BusyBox ash). As I expected.  But, quite UN expectly: This happens when the arithmetic  » -eq «  is being used (and some other). Prints all the four yes in , , , ,  and .  Q's  Is this the natural side effect of "Arithmetic Expansion" being applied to labels like (a) ?. (nothing to see, move along ?)  Should (a) still be expanded as a variable when quoted: "a"?  Is this documented somewhere I haven't look into yet?  Or, Is a simple (very old) bug?  Edit  To really get you thinking, check this:  a=2; b=2  [[ "$a" -eq "$b"                 ]] &amp;&amp; echo yes1 [[  $a  -eq "$b"                 ]] &amp;&amp; echo yes2 [[   a  -eq "$b"                 ]] &amp;&amp; echo yes3 [[  "a" -eq "$b"                 ]] &amp;&amp; echo yes4 [[ "$a" -eq "$b" &amp;&amp; "$a" == "$b" ]] &amp;&amp; echo new1 [[  $a  -eq "$b" &amp;&amp;  $a  == "$b" ]] &amp;&amp; echo new2 [[   a  -eq "$b" &amp;&amp;   a  == "$b" ]] &amp;&amp; echo new3 [[  "a" -eq "$b" &amp;&amp;  "a" == "$b" ]] &amp;&amp; echo new4   All yes work, only new1 and new2 do. The var a is not being expanded in new3 &amp; 4.  That means that shells switch mode (Arithmetic -- String) in the middle of the evaluation.  This doesn't seem so obvious to me. At least, is not simple, IMO.  Note that ash does it in a different way. And also report the error.  Conclusion:  I do not know the correct answer. But I suspect (looking at so many shells doing it exactly the same way) that it is a very well known way (to developers) in which this tests should work. It should be up to us to understand the fact and adapt.  Seems that for numeric -eq the only possible 'Conditional Expression' to apply is:  exp1 -eq exp2           true if exp1 is numerically equal to exp2.   Which makes both sides of the -eq "Arithmetic expressions"  While for the == the only possible 'Conditional Expression' to apply is:  string == pattern           true if string matches pattern. ....   Which makes the left hand side an string (no expansion?) and the right hand side a pattern (which really do not apply to the test I presented as all were quoted on the right side to avoid this complexity. So, right hand side defaults (being quoted) to an string also (no arithmetic expansion here).  But maybe I am more confused than I though :-)  What do you say?
29869
In php, I often need to map a variable using an array ... but I can not seem to be able to do this in a one liner. c.f. example:  // the following results in an error: echo array('a','b','c')[$key];  // this works, using an unnecessary variable: $variable = array('a','b','c'); echo $variable[$key];   This is a minor problem, but it keeps bugging every once in a while ... I don't like the fact, that I use a variable for nothing ;)
77376
var i : integer;  i := 1234567;   Given the above, I want the string "1,234,567" as output (assuming UK locale). IntToStr just gives me "1234567". I'm sure there's a one-liner for this, but I can't find it...
2846
Why does the following behave unexpectedly in Python?  &gt;&gt;&gt; a = 256 &gt;&gt;&gt; b = 256 &gt;&gt;&gt; a is b True           # This is an expected result &gt;&gt;&gt; a = 257 &gt;&gt;&gt; b = 257 &gt;&gt;&gt; a is b False          # What happened here? Why is this False? &gt;&gt;&gt; 257 is 257 True           # Yet the literal numbers compare properly   I am using Python 2.5.2. Trying some different versions of Python, it appears that Python 2.3.3 shows the above behaviour between 99 and 100.  Based on the above, I can hypothesize that Python is internally implemented such that "small" integers are stored in a different way than larger integers and the is operator can tell the difference. Why the leaky abstraction? What is a better way of comparing two arbitrary objects to see whether they are the same when I don't know in advance whether they are numbers or not?
76150
byte x = -1; for(int i = 0; i &lt; 8; i++) {     x = (byte) (x &gt;&gt;&gt; 1);     System.out.println("X: " + x); }   As I understand it, java stores data in two's-complement, meaning -1 = 11111111 (according to wikipedia).    Also, from the java docs: "The bit pattern is given by the left-hand operand, and the number of positions to shift by the right-hand operand. The unsigned right shift operator ">>>" shifts a zero into the leftmost position, while the leftmost position after ">>" depends on sign extension. "  Which means that >>> would shift a 0 to the left most bit every time.  So I expect this code to be  iteration: bit representation of x  0: 11111111  1: 01111111  2: 00111111  3: 00011111  ...so on  However, my output is always X: -1, meaning (I guess) that >>> is putting the sign bit in the left most position.  So I then try >>, and same result.  What's going on?  I would expect my output to be: X: -1, x: 127, x: 63, etc.