Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
My Software is JavaScript based. The code runs a query in an Oracle database and contacts the result as a string.
When gridData's size is bigger than 10 and some of the results return null, the execution time is slow.
Is this a code or query related problem ?
var related_approver="";
var tSql;
var tResult;
var extra_approver="";
gridData = Grid_RelateUnitObj.getData();
if (gridData.length > 0){
for (i = 0; i < gridData.length; i++){
tSql= "select users.id||'_'||users.username||';' from organizationunit,users where organizationunit.manageroid=users.oid and validtype=1 and"+" organizationunit.id='"+gridData[i][0]+"'";
tResult=tDbConn.query(tSql);
if (tResult.length>0)
{related_approver=tResult[0][0]+related_approver;
}
}
You might be better off writing one query fetching n rows rather than n queries fetching one row.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm trying to take an array of integers and cast it to bytes in JavaScript but can't quite figure out how to do it.
The input would look something like [2,-76,7,2,8,69,82,88,87,2,52,50,...].
If I was going to do it in another language like Java I'd use something like the following.
byte[] bytArr = new byte[intArray.size()];
for (int i = 0; i < intArray.size(); i++) {
bytArr[i] = (byte) intArray[i];
}
I'm pretty new to JS so not sure if this is even possible...
You can use Int8Array, which is a typed array.
const arr = Int8Array.from([2,-76,7,2,8,69,82,88,87,2,52,50]);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have been asked to show I have used these processes in my program but from looking up the definitions, I don't know what they mean. I am confident my program is complicated enough that it uses these processes, but I don't know exactly what they are. What would be an example of these processes used in javascript?
Unsure what you mean by custom function - but recursion is just a function that calls itself.
Example of recursion
countNumTimesToZero = (myNum, count = 0) => {
if (myNum - 1 === 0) return count + 1;
return countNumTimesToZero(myNum - 1, count + 1);
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Trying to generate a set of strings such as 'TCP', 'DNS' or 'SQL'
I want to be able to have these strings set and be able to have them appear randomly like you would with random numbers.
You can make an array and select them randomly:
const strings = ['TCP', 'DNS', 'SQL'];
for (var i = 0; i < 5; i++) {
console.log(`Random string: ${strings[Math.floor(Math.random() * strings.length)]}`);
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am getting below line in my source file and I would like to sum those values separated by pipe ("|")
There is no limit for the values coming in the line (might be 100 values)
10|20|30|40|[no limit for values] - Separator is pipe "|"
The ouptput would be 100
Please help to write a javascript function for the above query.
Regards
Jay
You should take a look at JavaScript's built-in functions: With split you can split your string into an array, with reduce you can 'reduce' your array to a single value, in that case via summation. These two links should provide you enough information for building your code.
You could try something like below:
function sum(value){
var total = 0;
var array = value.split(",").map(Number);
for( var i = 0; i < array.length; i++) {
total += array[i];
}
alert(total);
}
var value = "10|20|30|40".replace(/\|/g, ',');
console.log(sum(value));
https://jsfiddle.net/f7uqw7cL/
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
{"message":"hi","replay":"hello","messageFrom":253505936,"_id":"RFxx2j5jiHfvT7F8"}
{"message":"what is your name","replay":"kokokoko","messageFrom":322078970,"_id":"49leUECRRWrWdVc1"}
{"message":"no why","replay":"don't ask me","messageFrom":322078970,"_id":"7bb8DXqYTsPwq12n"}
{"message":"thank you","replay":"you'r welcome","messageFrom":200826832,"_id":"KrgmVquPDyqM6o7Z"}
this is a sample from my DB and I want to pick a random replay.
While not the most efficient solution, you can do something like this:
db.count({}, function (err, count) {
if (!err && count > 0) {
// count is the number of docs
// skip a random number between 0 to count-1
var skipCount = Math.floor(Math.random() * count);
db.find({}).skip(skipCount).limit(1).exec(function (err2, docs) {
if (!err2) {
// docs[0] is your random doc
}
});
}
});
Inspired by a similar approach for MongoDB.
Note that this solution suffers some of the same issues as the above; namely that it's not very efficient, and that there's a race condition if the number of records have changed between the getting the response to .count() and getting the response to .exec(). However, until NeDB supports something like $sample aggregation, I think this is the only option.