Javascript: find english word in string [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 7 years ago.
Improve this question
i want to find any english word (min 4 letters) in one string.
Eg: hello123fdwelcome => ["hello", "welcome"];
Could you suggest for me any solution or javascript lib to match english word.
Thanks

You can use this list of words https://github.com/dwyl/english-words
var input = "hello123fdwelcome";
var fs = require('fs');
fs.readFile("words.txt", function(words) {
var words = words.toString().split('\n').filter(function(word) {
return word.length >= 4;
});
var output = [];
words.forEach(word) {
if (input.match(word)) {
output.push(word);
}
});
console.log(output);
});

Related

How to split the number in js [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 have only one number like "100000"
I wan't to split this number same as [20000,20000,20000,20000,20000] in array
so if number is 138000 then it should be like [20000,20000,20000,20000,20000,20000,18000]
How to do this?
let num = 118000,
num_array = [];
while (num > 0) {
if (num >= 20000) {
num_array.push(20000);
num -= 20000;
} else {
num_array.push(num);
break;
}
}
console.log(num_array);
I think this is what you want, please post what you tried, so that it helps to understand where you failed.

How to split a text into an array of sentences (separated by full stop, comma, question mark etc) using Javascript/Jquery? [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 3 years ago.
Improve this question
I am trying to split the content of an article into its sentences.
For example, Splitting
"Hi, My Name is Mark. I am going to the store, Do you need anything?"
to an array like
["Hi," , "My Name is Mark." , "I am going to the store," , "Do you need anything?"]
Could you help with the code using split() ?
let str = "Hi, My Name is Mark. I am going to the store, Do you need anything?",
strArray = str.split(/[,.]/),
spliterArray = str.match(/[,.]/g),
newArray = [];
for (let [key, val] of strArray.entries()) {
let splitVal = spliterArray[key] ? spliterArray[key] : "";
newArray.push(val.trim() + splitVal);
}
console.log(newArray);

Shouldn't allow user to enter or copy/paste Emoji characters in any fields [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
my question is probably simple for most but its troubling me and ive been googling for sometime now.
I dont want allow copy or paste content and emoji characters in input fields.
var checkTf = function() {
let charcode_max = 255;
let tf = document.getElementById("tf");
for (let i = tf.value.length - 1; i >= 0; i--) {
if (tf.value[i].charCodeAt(0) > charcode_max) {
tf.value = tf.value.substr(0, i) + tf.value.substr(i + 1);
}
}
}
<html>
<head></head>
<body>
<textarea id="tf" oninput="checkTf()"></textarea>
</body>
</html>
You may increase charcode_max.
https://jsfiddle.net/qx4dt5bz/

While loop and Strings [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 5 years ago.
Improve this question
Var randomLetters = "ljhgfdza";
Var randomString = "";
Now I'll have to add elements in the first variable to the second Randomly
Using the while loop, and Math.floor(Math.random() * random letters.length)
I am having a problem at my
"While (condition)" what should it be?
To flat out answer your question, you can use:
while(randomLetters.length > 0){
Then when you use a letter from randomLetters, you delete the letter and the length is now 1 less.
This will be enough for you:
const randomLetters = "ljhgfdza";
const returnRandom = (randomString) => {
const arrString = [...randomString].sort((a, b) =>{
return 0.5 - Math.random()
}).join("");
console.log(typeof arrString,arrString);
}
returnRandom(randomLetters);
but... in this case sort method is not that random as you think. This link will tell you why. I would do this with reduce() or map(), both are described in link above.

Find an element that has a text value of 0? [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 7 years ago.
Improve this question
I need to find an element that's text value is 0.
I do:
var d = $('.content').find('div');
if(d.text().length === 0){
//do something
}
Is there a way to put the above logic in the selector?
I've tried:
var d = $('.content').find('div:empty');
But no luck as the div may have other empty html tags in.
Use a filter
var elems = $('.content').find('div').filter(function() { return $(this).text() == 0 });

Categories