(new Array(276959)).toString() results in commas - javascript

whenever I try to print an Array I get a lot of , and Chrome (my preferred browser) chokes the CPU.
How does it come, that it cannot print a simple Array to a string?

.toString() prints all values in the array from the first to the last values in order, separating each one by a comma.
new Array(276959) defines an array with 276959 empty entries, so the array itself has no values; it just has 276959 placeholders. When you use .toString(), there are no values to output, but the commas will still appear since the array has 276959 placeholders.

When you make
new Array(276959)
you are actually creating an array of 276959 values.
Since it doesn't have any content, each value is empty, so you only see the commas (separators) when you try to print it.

Related

Dealing with null values in #DBLookup

I have a domino view with an amount column but some values are empty...and need to be. The problem is that the #Sum works fine until I have an empty value then it stops summing.
eg: if the values are 5,5,"" and 5 I get a sum of 10 and not 15.
I've traced the problem to the #DbLookup which is that it stops building the return array when it encounters a blank value. There is no built in method of dealing with null values.
https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/reference/r_wpdr_atfunctions_dblookup_r.html
To make things harder, #dbLookup returns a string if only one is found or an array if more than one are found. If the values are 5,5,"" and 5 it returns an array of 2 values.
var alloc = #Sum(#DbLookup(#DbName(), "SubForms",MainFrmID , "ca_ca_ca_ca_amount"));
if (isNaN(alloc)){
return "$0.00";
}else{
return "$" + alloc.toFixed(2);
}
Can anyone help me refactor the #sum or #DbLookup to allow for empty values? Unfortunately I cannot define any new functions for this solution. The environment is locked down tightly. With a list of values of 5,5,"" and 5 I need a sum of 15.
I would try #Sum(#TextToNumber(#Trim(#Text(#DbLookup(...)))))
I would try
#Sum( #Transform( #Dblookup ( ....
If #DbLookup does not do what you need, you could always iterate over documents or view entries to build the sum.
The flow would be roughly like this:
1. Get a handle to the current database.
2. Get a handle to the "SubForms" view.
3a. Get a view entry collection using using getAllEntriesByKey() with MainFrmID as key, if a view column exists that displays the values you need.
--OR--
3b. Get a document collection using getAllDocumentsByKey() with MainFrmID as key, if no view column exists that displays the values you need.
4. Iterate over the collection to sum up values, using getColumnValues().get(columnNumber) to access the value from each view entry, or getItemValueDouble(fieldName) to access the value from each document.
That way you can easily detect null values and discard them.

Emitted Values Being Sent as One String Instead of Individual Values

In my Angular app I'm returning results via an API call, and allowing users to filter those results through a series of checkbox selections. Right now I'm running into an issue where, while results are returned as expected when one value is sent for a certain filter, when multiple values are selected (like filtering by more than one zipcode, for instance) I get zero results printed to the view. No errors, just no results.
After scratching my head for a while, using Chrome devtools network tab, I finally determined that the problem is that rather than wrapping each item in quotes in the payload - like this: "90001", "90002", what's being sent is this: "90001, 90002". In other words, quotes are wrapped around as if it were one value, not two.
This is the code, where I'm using a "join" to put together the values that are selected:
this.sendZipcode.emit(this.zipcodeFilters.text = arr.length === 0 ? undefined : arr.join(','));
I'm not sure how I can adjust the way this "join" is constructed, or find some other solution instead of "join", in order to have each item wrapped in quotes, rather than wrapped like one long string.
FYI, this is what I see in the network tab of Chrome devtools after selecting two zipcodes. As I explained, it's wrapped like one string, rather than as two values:
addresses.zipCode: {$in: ["90001, 90002"]}
Array.prototype.join will return a string. So you are converting your array to a single string which is being sent as a string. You want to send an array. Simply remove the join call and return arr directly.
String: "value, value"
Array: "value", "value"

How can I work with the Name of an Array?

Situation: I have an array called "array1" with some strings in it.
For example, when I type array1.length , then the program gives me the amount of strings in the array back. What do I have to do to get "6" back (The amount of letters in the array name "array1")
maybe you could youst wrap the arrays with numbers in one array and the other ones in another array and just use the wrapper array you need.
without seeing your code this is the best solution i can give you

how to filter out non-numeric values

I have a table (in a RethinkDB database) that has a bunch of documents with the field VIN0. This field almost always stores numbers, as intended.
I had some data corruption recently where there are some strings in place of numbers for the field VIN0. Queries I was using to manipulate this data now return the error: "e: Expected type NUMBER but found STRING in:"
I'd like to filter for the strings, but I can't seem to find them. Is there a way to use something like Number.isInteger() to filter out these items within RethinkDB?
Thanks!
You can use typeOf to find type of a field, or a element. Let's say you want to filter document with VIN0 is a number
r.db('db').table('table').filter(r.row('VIN0').typeOf().eq('NUMBER'))
You can also try to correct problem by using coereTo to convert string to number.
r.db('db').table('table')
.filter(r.row('VIN0').typeOf().eq('STRING'))
.update({VIN0: r.row('VIN0').coerceTo('NUMBER')})
Hope this helps.

No output when parsing textarea with JavaScript

I have a text box that will have a large block of text pasted into it.
Then I parse the text into an array, removing whitespace. I need to pull the data out of certain array elements and put them into separate variables so I can generate a cleaner, formatted output.
The problem is that noting appears to be passed into my variables from the array. I've toyed with it a bit, and the array is being filled correctly, but the elements aren't passing strings to the variable.
HTML:
<p>Contact Name: <b id='contactNameOutput'></b></p>
JavaScript:
function generateOutputfvoc() {
var inputArr = document.getElementById('inputBox').value.split(/[\s]/);
document.getElementById('contactNameOutput').innerHTML = inputArr[0];
}
There are quite a few things going on here wich are hard to understand why you've done them.
My asumption is that inputBox is either a textarea or a input field into wich the user writes something.
Okay so you're splitting that string on whitespaces so for example the string
The quick brown fox
would result in a array which looks like this:
inputArr = ["The", "quick", "brown", "fox"]
Now in your for-loop you're iterating over this array, starting at 0 and incrementing till you reach the end of the array, nothing strange here.
But in the first iteration, in the if-clause that you have, you're trying to access the array with negative values, remember i is 0, this results in an undefined value, also in the last part of the if clause you're trying to access i+1 well what happens when i is at its last value?! You guessed it another undefined! Later the loop will access old values which you've allready gone through, and honestly I can't figure out what you're trying to accomplish.
All your if-statements are a mess really, especially if your gonna do them in that loop.
My guess is that you thought that you needed a for-loop for this, when in fact you do not.
What you have is one array containing the words in your textarea, if you know the order of what you're expecting, (can you really know what the user will put in that textarea?), then you can just access the words directly since you'll know the index of each item in the array. Otherwise, rewrite this to something simpler, always try to keep it simple.
Also why not look up refactoring while you're at it?!
edit
I think that the problem you have now is that the first element in the array is an empty string, that happens if there's a space in the beginning of the input.

Categories