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 6 years ago.
Improve this question
Can you give me an idea may be using javascript, jquery or angular
I am generating three random array
for eg:
(This values are generating using random array =['member', 'medical', 'rx', 'disability'];)
and output
member disability medical disability
medical member disability rx
disability disability medical member
disability member member disability
how do i calculate whether which value is in all column and maximum occured
for example disability is the answer
thanks
In JS you can use JSON to count the number of occurring of a word in your arrays:
var countArr = [
{"word":"member", "occur":0},
{"word":"disability ", "occur":0}
];
var All = random1.concat(random2).concat(random3);
for(i = 0; i < All.length; i++){
count(All[i]);
}
function count(word){
var x = countArr.findIndex(function(elm){ return elm.word == word;});
if(x != -1){
++countArr[x].occur;
}
else{
countArr.push({"word":word, "occur":0});
}
}
and you can easily add more details to your JSON about your word for example the index of occurring a word in your arrays.
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 3 years ago.
Improve this question
I'm writting an score board app.
Got two integers, i need to compare them, for example
to know when game should be ended, eg. score = 20:22, 24:26 (score difference to end the game should be equal to two)
How i can make such comparison with js?
You can use split() method to separate scores into two different elements, and then afterwards just compare them.
function isGameOver(score, differenceToWin) {
var scoreArray = score.split(":");
return Math.abs(scoreArray[0] - scoreArray[1]) > differenceToWin;
}
isGameOver('24:26', 2)
EDIT: In case you only need to compare two integers, go ahead and use only the return statement line:
var score1 = 24;
var score2 = 26;
var differenceToWin = 2;
var isGameOver = Math.abs(score1 - score2) > differenceToWin;
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 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.
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 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 9 years ago.
Improve this question
I want to implement a small code I am not able to understand from where to start. I want to create a text field if user enter some text into text field I want to detect category of this text. For example if user enter "How to create an app for iOs".. utlity should detect this category as information technology. another example "good hotels in Singapore" this utility should detect treat this category as Travel....
My idea to create library with words.
var categories = new Object();
categories = {
'IT' : {'iOS', 'Android'},
'Travel' : {'USA', 'London', 'Singapore'}
};
var text = 'How to create an app for iOs';
var spitter = text.split(' ');
for (var i = 0; i < spitter.length; i++) {
var word = spitter[i];
for (var categoryKey in categories) {
for (var categoryKeyWord in categories[categoryKey]) {
var regExp = new RegExp(categories[categoryKey][categoryKeyWord], i);
if (regEpx.match(word) {
//Your logic
}
}
}
}