## Function to check whether a combination of letters appears in a sequence of random words and determine where exactly are they

check if words are sorted according to new order of alphabets
find anagrams in a list of words python
find all anagrams in a list of words java
print all pairs of anagrams in a given array of strings
given millions of words, return all groups of strings that are anagrams
group anagrams python
sorting on a custom alphabet pure storage
find all anagrams of a word

I created a function in javascript to generate a random string with a certain length in either uppercase/lowercase or both.

```    function randomString(max, option) {
var rNum = [];
if (option.toLowerCase() === "lowercase") {
for (let i = 0; i < max; i++) {
var randomNumber = Math.floor(Math.random() * (122 - 97) + 97);
rNum.push(randomNumber);
}
} else if (option.toLowerCase() === "uppercase") {
for (let i = 0; i < max; i++) {
var randomNumber = Math.floor(Math.random() * (90 - 65) + 65);
rNum.push(randomNumber);
}
} else if (option.toLowerCase() === "both") {
for (let i = 0; i < max; i++) {
var n = Math.floor(Math.random() * (122 - 65) + 65);
while ([91, 92, 93, 94, 95, 96].includes(n)) {
//If the random number is between 90 and 97 then we keep generating new numbers:
n = Math.floor(Math.random() * (122 - 65) + 65);
}
rNum.push(n);
}
} else {
return "Second parameter not valid, please type 'lowercase','uppercase' or 'both'";
}
var word = "";
for (let i = 0; i < rNum.length; i++) {
var letter = String.fromCharCode(rNum[i]);
word += letter;
}
return word;
}
```

Now I wanted to create a second function that given any string from the user, it checks whether that word appears in the randomly generated string.

I started it and honestly I simply have no idea how to do it. How do I check where in that long string there is indeed the word which I don't know how long it is. I guess it can see if it does exist or not, but how do i find its position? I tried using `array.indexOf(userString)`, but it only returns the first time it appears.

```function findWordsByChance(letters) {
var myString = randomString(999999, "both");
var splited = myString.split("");
if (splited.includes(letters)) {
console.log("this combination exists");
} else {
console.log("it doesnt");
}

for (let i = 1; i < splited.length - 1; i++) {
//check where it is (??)
}
}
findWordsByChance("Hi");
```

I'm still quite new to programming, so give me a break if I made any stupid mistakes :) btw, if you guys got any tips on how to do something I already did but in a more efficient way, I'd appreciate.

`indexOf` accepts a second parameter which defines a start offset, so you can use this to loop through and find every occurrence. You just need to make the start point immediately past the last occurrence for each iteration. Here's how I'd write the function:

```function indexOfAll(needle, haystack) {
var indices = [];
var index = 0;
while ((index = haystack.indexOf(needle, index)) > -1) {
indices.push(index);
index += needle.length;
}
return indices;
}

console.log(indexOfAll("oat", "goat in a boat"));```

Given a sequence of words, print all anagrams together, Populate the Hash Table with these hash values. Following is another method to print all anagrams together. Take two auxiliary arrays, index array and word array. Populate the word array with the given sequence of words. of the characters of each string and the outer HashMap will check whether that� In particular, for any possible random result (a sequence of 64 hexadecimal characters), it is impossible to find a data file F with this fingerprint in a reasonable amount of time. There have

You can use the simple .match() function in javascript to find a string in another string.

```var myString = randomString(100, "both");
// myString = "fAuqxBfkXprhvRqOGLPmTiFbhrZtjXXMFwircAGBBtIkiDbGHPvYymMlabJyeAKUtIYNedUpNPlaeEcjIsSeEtOUriHTuCtbpNZX"

var result = myString.match('rZtjX');
// result is your search string...the "letters" value
// result is where the string was found

// If you want to get all occurrences where the search string was found you can use the function below.

findOccurrences = (needle, haystack) => {
const pieces = haystack.split(needle);
if (!pieces.length) {
return console.log('No Matches');
}
let index = 0;
pieces.forEach((piece) => {
index += piece.length;
console.log(needle, ' found at ', index);
index += needle.length;
});
}
findOccurrences('LPmT', myString);
LPmT  found at  17
LPmT  found at  47
LPmT  found at  81
LPmT  found at  99
LPmT  found at  112
```

Combinations and Permutations, For example, there are 6 permutations of the letters a, b, c: How many 4 letter “ words” can you make from the letters a through f, with no repeated letters? A BLAST alignment consists of a pair of sequences, in which every letter in one sequence is paired with, or “aligned to,” exactly one letter or a gap in the other. The alignment score is computed by assigning a value to each aligned pair of letters and then summing these values over the length of the alignment.

You could turn their input into a regex.

```const inputRegex = new RegExp(input, 'g')
```

Then you could use `string.matchAll()` to get all instances of matches.

```const matches = randomLetters.matchAll(inputRegex)
```

But that gives you an iterator. To have it as an array, you'd do this instead:

```const matches = [...randomLetters.matchAll(inputRegex)]
```

Now, each item in matches is an object with a key `index` referring to its position on the string.