Nodejs - Read values of array as number instead of string - node.js

I created an array inside my own class in nodejs to store real values.
this.values = new Array();
and almost every second a new value is pushed to this array.
this.values.push(Number(dataset.c).toFixed(4));
Finaly I have a function where I need to provide the array in the argument list to do bollinger band calculation. This function need an array filled with real or integer values but in my array every value is stored as an string.
Is it possible to change this storage behaviour or how can I 'typecast' all the values in this array?
Best regards

Found a solution using the map-Function.
this.values.map(Number)
did the job.

Related

Unity: Comparing strings doesn't seem to work in this case?

I'm trying to compare to strings in a function to be able to do stuff if it's true. However, for some reason the two strings I'm comparing are never equal to eachother.
I am creating a new string in a function, getting data from a Json and then comparing that string with another string in another class. This doesn't work for some reason. The Debug shows that both strings are equal, but the if-statement returns false.
I created two other string variables (hello & hello2) with the same value ("Hello") and this time it's comparing correctly.
Check the images below. What am I doing wrong?
As you can see in the console, both strings have the same value:
Image 1. Here's where I create the string (zoneId).
Image 2. Further down in the same function, same for-loop.
Here's where I'm trying to compare the string created in this function with another string from another class.
Image 3. As you can see in the console it's looping through the jsonArray. But it's returning false even though it's clear that both strings have the same value.
Image 4 and 5. Here I am testing with two other strings inside the function and they are working fine.
Does it has something to do calling a string from another class?
Here's how my other string in userInfo is set up:
public string userID { get; private set; }
In Image 3, is there an additional space before the second 2?
How are you processing Main.Instance.userInfo.zoneID?
You need to use string.Equals for string comparison instead of operator == or !=.
Are string.Equals() and == operator really same?

How to convert a string array into floats in PHP

I'm selecting some Strings from my SQLite DB and store them in an Array. Now I want to plot the values with the framework "Razorflow". I think it is only possible if the values of the array are floats, am I wrong?
In my DB I'm storing temperature and humidity of 12 different sensor nodes, in this form:
id|temperature|humidity|...|...
1 | 22.50C| 47.50%|...|...
..
I heared something about the floatval()-function, I also heared that this function is not made for objects like Arrays. Is there a simple solution? I'm very new to PHP :-D
Depends on how you're getting the values back from the database.
id|temperature|humidity|...|...
Sounds like a string to me, so i would first explode it into an array and then iterate the array casting floatval into every element.
What you do after that process depends on you.
EDIT:
If your query is:
$humi = $database->query((SELECT humidity FROM Measurement WHERE topic_hum='WSN9/humi'
You will get back only 1 column (humidity) and 0 or more rows depending on your database. Let's say it's only 1 for now:
$resul = mysql_query($humi,$link);
$rows = mysql_fetch_array($resul);
$myarray = explode("|", $rows["humidity"]);
This should give us an array called myarray containing X elements each with a "single" string part value. So we can iterate over it and parse it. There is also the shorthand "array_map" to iterate over an array using a callback function over each element and returning the value as an array:
$myparsedarray = array_map('floatval', $myarray)
Now you have an array with only float values (and errors maybe, check your data!)

How do I append a value to results of #DBlookup in xpages?

How do I append a value to results of #DBlookup in xpages?
I tried this but it does not seem to work.
var v = #DbLookup("","Setup","Setup","ModRationales").push("Other 2");
return v;
It shows 6.0 in my listbox.
First of all: #DbLookup returns a string when it looks up one value only, and it returns an array when it finds multiple values. I will therefore suggest that you use the DbLookupArray() function available as a xsnippet as this function always returns an array. It has other advantages too such as optional caching of the result.
Then it is just a matter of adding elements to the array using .push() on the result returned by DbLookupArray().
Your current lookup is most likely returning a single element - which in the case of #DbLookup is a string.
Got it:
var v = #DbLookup("","Setup","Setup","ModRationales");
v.push("Other");
return v;

an efficient way acess a range in a user defined type?

I've got a user defined type with about 5000 entries. I would like to select a range of the data in about 1,000 entry blocks and use it as an array. Is there a way to do this without looping?
Something like
MyArray = MyType(1:1000).property
rather than
for i = 1 to 1000
MyArray(i) = MyType(i).property
Next i
Thanks!
No, there is no way to convert a collection of elements into an array without looping or special accessor methods for the type - let alone convert a common property from a collection of elements into an array.
The only objects that support anything like this are Range objects, for which you can convert certain properties of an array of cells (range) into an array using:
MyArray = Range("A1:A1000").Value
Again, nothing like this is available for other types unless the programmer goes through the trouble of defining the behaviour - and even if they did define it, odds are the method would likely include iterating over the elements anyways, just within the type class.

IDL: Accessing struct fields using field names stored in variables?

If I have a struct with a fieldname 'fieldname', is it possible to access the data in that field using only the variable?
ie.
x = 'fieldname'
is it possible to do
data = struct.(x) in some way? I want to use the string in x as the field name.
Yes, this is possible using the TAG_NAMES function:
tnames=TAG_NAMES(struct)
tindex=WHERE(STRCMP(tnames,'fieldname') EQ 1)
data=struct.(tindex)
The call to TAG_NAMES returns an array of strings representing the tags defined in struct.
The WHERE statement returns the index in tnames of a string matching 'fieldname'.
Finally, the index is passed to the struct.(tindex) operation, which extracts a field by
its numeric tag index.
Of course, in a real application you'd want to check whether tindex was successfully
matched to something, otherwise IDL will choke on the structure lookup with an index
of -1.

Resources