Need guidance to make small utility based on user inputs [closed] - javascript

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
}
}
}
}

Related

How to get a child key value in Firebase Realtime Database [closed]

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 3 years ago.
Improve this question
I'm new with Firebase and I'm currently using JavaScript SDK to integrate my web application with Firebase.
My question is: How to get value within the red box that I drew on the image?
I am using
snapshot.key
to access the key valuebut it returns the generated key (blue box) to me which is not the one I wanted.
Based on your comments, it is not 100% clear what you are looking for. If you know that you have a sub-node with the key speechtext under the recording parent node with key LRC2o.... you don't need to query for getting the key of this sub-node (since you know it).
If, on the other hand, you want to iterate on all the keys of the sub-nodes of the recording node, do as follows (based on your code):
var dbRecording = firebase.database().ref("recordings/");
dbRecording.once("value", function(snapshot2) {
if (snapshot2.exists()) {
snapshot2.forEach(function(value) {
var childObject = value.val();
Object.keys(childObject).forEach(e => console.log(`key = ${e}`));
});
}
});
If you want the keys and the values, do as follows:
var dbRecording = firebase.database().ref("recordings/");
dbRecording.once("value", function(snapshot2) {
if (snapshot2.exists()) {
snapshot2.forEach(function(value) {
var childObject = value.val();
Object.keys(childObject).forEach(e => console.log(`key = ${e} value = ${childObject[e]}`));
});
}
});

Javascript function output (deobfuscation) [closed]

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 4 years ago.
Improve this question
I have come across this code in a web page from a CTF game:
function conexion() {
var Password = "unescape(String.fromCharCode%2880%2C%20108%2C%2097%2C%20110%29):KZQWYZLOMNUWC===":
for (i = 0; i < Password.length; i++) {
if (Password[i].indexOf(code1) == 0) {
var TheSplit = Password[i].split(":");
var code1 = TheSplit[0];
var code2 = TheSplit[1];
}
}
}
After working a little bit, I have deobfuscated the Password line and obtained:
unescape(String.fromCharCode(80, 108, 97, 110)):KZQWYZLOMNUWC===
which was also translated to Password = "Plan:KZQWYZLOMNUWC===";.
My first reading of the code is that code1 = Plan and code2 = KZQWYZLOMNUWC.
But this is not the correct answer. I’m also not sure how the === operates here.
May you please give me some insights?

Need idea how to implement it [closed]

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.

Random Username Generator Javascript [closed]

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 2 years ago.
Improve this question
I'm currently using Visual Studio to build my website and I'm getting stuck on my username generator. I need it because I don't want any inappropriate words and this is a children's website so I don't want to use real information. I thought about using an array of strings and then adding them together but for some reason, I can't get it to work -__- any help would be appreciated. I'm in coding boot camp and my teacher said this would be a useful place for information. Thanks.
So far, this is what I have:
var a = ["Small", "Blue", "Ugly"];
var b = ["Bear", "Dog", "Banana"];
var rA = Math.floor(Math.random()*a.length);
var rB = Math.floor(Math.random()*b.length);
var name = a[rA] + b[rB];
alert(name);
Now my issue is I'm trying to write a function that will generate a new name with every click. I know I need function myFunction() and an onclick= event. Hopefully this is not a vague as before.
You can try something like this, (looking at comments)
var a = ["Small", "Blue", "Ugly"];
var b = ["Bear", "Dog", "Banana"];
var rA = Math.floor(Math.random()*a.length);
var rB = Math.floor(Math.random()*b.length);
var name = a[rA] + b[rB];

How can you count the number of occurrences of all of the words in a text area using Javascript? [closed]

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 8 years ago.
Improve this question
If I had a textarea and a user pasted a paragraph into the textarea, can statistics be run on the input using JavaScript on the client side? I was thinking of using an associative array or hash map so array[word] -> # of occurrences, and iterate through word by word but I'm not sure how to do this using client side JavaScript.
I tried searching JavaScript word count but I only get results on counting the total number of words, which is not what I'm looking for. What I am looking for is more keeping a count of each specific word. Can this be done in Javascript or Jquery? If so, how should I go about doing this?
Here is an approach for you
// first get an array of words
var words = text.split(' ');
// use Array.prototype.reduce (for example) to
// create statistics
var statistics = words.reduce(function (stat, word) {
if (!stat[word]) stat[word] = 0;
stat[word]++;
return stat;
}, {});
UPDATE: A little example which handles punctuation and upper/lower case, too: http://jsfiddle.net/1pnLzv8h/1/
Something like
var arra = ['ab','pq','mn','ab','mn','ab']
function wordCount(arra,val)
{
var ob={};
var len=arra.length;
for(var k=0;k<len;k++)
{
if(ob.hasOwnProperty(arra[k]))
{
ob[arra[k]]++;
continue;
}
ob[arra[k]]=1;
}
return ob[val];
}
alert(wordCount(arra,'ab')); //output 3

Categories

Resources