This commit is contained in:
nazizmari 2024-07-17 10:43:11 +09:00 committed by GitHub
commit d1d8cd6942
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,51 @@
 function combsort(arr)
{
 function is_array_sorted(arr) {
      var sorted = true;
      for (var i = 0; i < arr.length - 1; i++) {
          if (arr[i] > arr[i + 1]) {
              sorted = false;
              break;
          }
      }
      return sorted;
  }
 
  var iteration_count = 0;
  var gap = arr.length - 2;
  var decrease_factor = 1.25;
 
  // Repeat iterations Until array is not sorted
  
  while (!is_array_sorted(arr)) 
  {
      // If not first gap  Calculate gap
      if (iteration_count > 0)
         gap = (gap == 1) ? gap : Math.floor(gap / decrease_factor);
 

View File

@ -0,0 +1,51 @@
function markovChainGenerator(text) {
const textArr = text.split(' ')
const markovChain = {};
for (let i = 0; i < textArr.length; i++)
 {
let word = textArr[i].toLowerCase().replace(/[\W_]/, "")
if (!markovChain[word])
 {
markovChain[word] = []
}
if (textArr[i + 1]) 
{
markovChain[word].push(textArr[i +1].toLowerCase().replace(/[\W_]/, ""));
}
}
return markovChain
}
function likelyhood(chain, prev, word) 
{
const prevArr = chain[prev]
const num = prevArr.filter
(w => w === word).length
return `The likelihood that ${word} will come after ${prev} is ${num} out of ${prevArr.length}`}