Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
How to get a array sequency?

Im trying to verify last messages of my users, and verify if he is using selfbot in my application.

var array = ["a", "b", "c", "f", "b", "a", "b", "c", "f", "b", "a", "b", "c", "f", "b", "a", "b", "c", "f", "b", "a", "b", "c", "f", "b"];

// ["a", "b", "c", "f", "b"] is the sequency, selfbot detected?

I tried using this, but i do not know how to proceed now

var array = ["a", "b", "c", "f", "b", "a", "b", "c", "f", "b", "a", "b", "c", "f", "b", "a", "b", "c", "f", "b", "a", "b", "c", "f", "b"];

let counts = {};
array.forEach(x => { counts[x] = (counts[x] || 0) + 1; });
console.log(counts);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can loops with recursion like this:

/*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/
const array = [
  'a',
  'b',
  'c',
  'f',
  'b',
  'a',
  'b',
  'c',
  'f',
  'b',
  'a',
  'b',
  'c',
  'f',
  'b',
  'a',
  'b',
  'c',
  'f',
  'b',
  'a',
  'b',
  'c',
  'f',
  'b',
];

let num = 0;
(function findSeq(seqStart = 0, seqEnd = 0, i = 0, j = -1) {
  while (++i < array.length && array[i] !== array[seqStart]);
  seqEnd = i;
  while (++j < seqEnd && array[i++] === array[j]);
  if (seqEnd === j)
    console.log(
      `Sequence ${++num} found between`,
      seqStart,
      seqEnd,
      array.slice(seqStart, seqEnd)
    );
  if (i < array.length) findSeq(seqEnd, 0, i - 1, j - 1);
})();
console.log(`${num} sequences found`);
<!-- https://meta.stackoverflow.com/a/375985/ -->    <script src="https://gh-canon.github.io/stack-snippet-console/console.min.js"></script>

about 4 years ago · Juan Pablo Isaza Denunciar

0

One way is to check one by one (perhaps not the most efficient):

var sequence = ["a", "b", "c", "f", "b"]; // Sequence that shows whether user is bot

// Test cases
var array1 = ["a", "b", "c", "f", "b", "a", "b", "c", "f", "b", "a", "b", "c", "f", "b", "a", "b", "c", "f", "b", "a", "b", "c", "f", "b"];
var array2 = ["b", "a", "b", "b", "f", "c", "a", "b", "c", "d", "e", "f", "a", "f", "c", "c", "c", "c", "f", "a", "a", "b", "b", "e", "e"];

function selfBotDetector(arr, seq) {
  // Function to check if sequence matches given range
  var check = start => {
    for(var t = start; t < seq.length + start; t++) {
      if(arr[t] !== seq[t - start]) {
        return false;
      }
    }
    return true;
  };
  for (var i = 0; i < arr.length; i++) {
    var result = check(i);
    // If at any time the sequence matches return true
    if(result)
      return true;
  }
  // if true was never returned then the sequence did not match
  return false;
}

console.log("Array 1:", selfBotDetector(array1, sequence) ? "Selfbot detected" : "OK");
console.log("Array 2:", selfBotDetector(array2, sequence) ? "Selfbot detected" : "OK");

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda