I was resolving some problems on codewars and tried to convert a string to a list of numbers like this:  "102904".split("").map(parseInt);   The expected result would be something like this:  [1, 0, 2, 9, 0, 4]   But it returns instead:  [1, NaN, NaN, NaN, 0, 4]   At believe that map should apply to each element in the list which are strings of 1 digits. One could believe that it isn't parsing correctly because the base isn't used but:  "102904".split("").map(function(x){ return parseInt(x);}); [ 1, 0, 2, 9, 0, 4]   Using parseInt(x, 10), doesn't change the result. But sending directly parseInt to map creates NaN...  I tried on Chrome and Firefox and I receive the same results.
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]
23131
What is the best way to convert a JSON code as this:  {      "data" :      {          "field1" : "value1",          "field2" : "value2"     } }   in a Java Map in which one the keys are (field1, field2) and the values for those fields are (value1, value2).  Any ideas? Should I use Json-lib for that? Or better if I write my own parser?
38760
I have a comma-separated list of data points. They should be plotted as a scatter plot, and should be labeled using data from the .csv file. Having specified the first column of my file as string type, I still keep running into errors saying Could not parse input [...] as a floating point number, sorry.  Given a CSV file of the following format, how can I read Name and Z as labels?  Name,X,Y,Z ODIN,250,45,2001   Here is my MWE:  \documentclass{article}  \usepackage{tikz,pgfplots,pgfplotstable}     \pgfplotsset{compat=1.5.1}  \begin{document}  \pgfplotstabletypeset[columns/Name/.style={string type}]{table.csv};  \begin{tikzpicture}     \begin{axis}[     visualization depends on=\thisrow{Name} \as \labela,     visualization depends on=\thisrow{Z} \as \labelb,     every node near coord/.append style={font={\tiny}},     nodes near coords=\labela/\labelb,     nodes near coords align={horizontal},]      \addplot[only marks] table [x=X,y=Y,col sep=comma] {table.csv};      \end{axis} \end{tikzpicture}  \end{document}   Note that if the data in column Name is just floats it should work fine.
12281
I entered this statement in JSLint:  var number = new Number(3);   And received the following message:     Do not use Number as a constructor.   Why is that? The statement is creating a number object, not a primitive value, so I don't see why using new is a problem.  EDIT: Thanks for all the responses. They've got me thinking further, so I posted a follow-up question .
14414
I am trying to convert an integer number in C into an array containing each of that number's digits  i.e.  if I have   int number = 5400   how can I get to   int numberArray[4]   where   numberArray[0] = 0; numberArray[1] = 0; numberArray[2] = 4; numberArray[3] = 5;   Any suggestions gratefully received.
97702
I'm trying to split a string with all non-alphanumeric characters as delimiters yet Java's String.split() method discards the delimiter characters from the resulting array. Is there a way to split a string like the "\W" regex pattern does, yet keep the delimiters?
2272
I have a list with 15 numbers in, and I need to write some code that produces all 32,768 combinations of those numbers.   I've found  (by Googling) that apparently does what I'm looking for, but I found the code fairly opaque and am wary of using it. Plus I have a feeling there must be a more elegant solution.  The only thing that occurs to me would be to just loop through the decimal integers 1–32768 and convert those to binary, and use the binary representation as a filter to pick out the appropriate numbers.   Does anyone know of a better way? Using map(), maybe?
24659
I have a string of digits, e.g. "123456789", and I need to extract each one of them to use them in a calculation. I can of course access each char by index, but how do I convert it into an int?  I've looked into atoi(), but it takes a string as argument. Hence I must convert each char into a string and then call atoi on it. Is there a better way?
17519
I have a string containing the , and I need to convert it to a Java Date object.  String date = "1081157732"; DateFormat df = new SimpleDateFormat(""); // This line try {   Date expiry = df.parse(date);  } catch (ParseException ex) {   ex.getStackTrace(); }   The marked line is where I'm having trouble. I can't work out what the argument to SimpleDateFormat() should be, or even if I should be using SimpleDateFormat().
41144
As made clear in update 3 on , this notation: var hash = {}; hash[X]  does not actually hash the object X; it actually just converts X to a string (via .toString() if it's an object, or some other built-in conversions for various primitive types) and then looks that string up, without hashing it, in &quot;hash&quot;. Object equality is also not checked - if two different objects have the same string conversion, they will just overwrite each other. Given this - are there any efficient implementations of hashmaps in JavaScript? (For example, the second Google result of  yields an implementation which is O(n) for any operation. Various other results ignore the fact that different objects with equivalent string representations overwrite each other.
54515
I want to implement numbering scheme like Microsoft Word uses for numbering.  first one gets = A,next is  B, next is C, .... then AA, then AB,....and so on.  as shown below   A        B  C  .   .  AA  AB  AC  .  .  AAA  AAB  ....   '=>' here means converted to.  some examples:       1 =&gt; A 26 =&gt; Z 27 =&gt; AA 52 =&gt; AZ 53 =&gt; BA   and heres the code for it:     var convertToNumberingScheme = function(n){         var x = n-1,             r26 = x.toString(26),             baseCharCode = "A".charCodeAt(0);          var arr = r26.split(''),             len = arr.length;          var newArr =arr.map(function(val,i){             val = parseInt(val,26);              if( (i === 0) &amp;&amp; ( len &gt; 1)){                 val = val-1;             }              return String.fromCharCode(baseCharCode + val);         });         return newArr.join('');     }   It seems to work fine, but any ideas if there are some potential bugs or ways to  optimize this.
271
How do you left pad an int with zeros when converting to a String in java?  I'm basically looking to pad out integers up to 9999 with leading zeros (e.g. 1 = 0001).
57572
I normally use the following idiom to check if a String can be converted to an integer.  public boolean isInteger( String input ) {     try {         Integer.parseInt( input );         return true;     }     catch( Exception e ) {         return false;     } }   Is it just me, or does this seem a bit hackish?  What's a better way?    See my answer (with benchmarks, based on the  by ) to see why I've reversed my position and accepted  to this problem.  I think this original code will be used by most people because it's quicker to implement, and more maintainable, but it's orders of magnitude slower when non-integer data is provided.
26280
What is an easy way in Python to format integers into strings representing thousands with K, and millions with M, and leaving just couple digits after comma?  I'd like to show 7436313 as 7.44M, and 2345 as 2,34K.  Is there some % string formatting operator available for that? Or that could be done only by actually dividing by 1000 in a loop and constructing result string step by step?
52590
When I have a Set of Id's and I want to do a dynamic SOQL query that I want to use it in for an IN comparison, I have to convert the Set to string in the format of:  ('id1','id2',id3',...)   The way I do it works, but is not particularly elegant, so I'm wondering if anyone has come up with a better way. Am I missing something? Is there something out there that can just turn a set or list into the properly formatted string?   Here's my code (yes, my example isn't dynamic SOQL, but I've used this several times in dynamic SOQL):   Map&lt;Id,Account&gt; accts = new Map&lt;Id,Account&gt;([select Id from Account]);  String idString = '(\''; for (Id thisId : accts.keyset()) {     idString += thisId + '\',\''; } idString = idString.substring(0,idString.length()-2); //&lt;--this is the bit I hate doing idString += ')';  String q = 'select id from Contact where AccountId in ' + idString;  List&lt;Contact&gt; cts = Database.query(q);
27564
The code below generates:    What I expect is:    Why does the \foreach seem to treat the entire list as one value? How do I fix it?  \documentclass{article} \usepackage{xparse} \usepackage{xstring} \usepackage{etoolbox} \usepackage{expl3} \usepackage{tikz}  \begin{document}  \ExplSyntaxOn  \DeclareDocumentCommand{\separate}{m} {   \StrLeft{#1}{1}[\head]   \StrBehind[1]{#1}{\head}[\tail]   \IfInteger{\tail}{\head,\separate{\tail}}{\head} }  \DeclareDocumentCommand{\map}{m} {   \def\list{#1}   \foreach \i in \list   {     [\i]   } }  \ExplSyntaxOff  \def\arg{3669887}  \arg  \separate{\arg}  \map{\separate{\arg}}  \end{document}
11789
I'd like to convert a float to a whole number in JavaScript. Actually, I'd like to know how to do BOTH of the standard conversions: by truncating and by rounding. And efficiently, not via converting to a string and parsing.