Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!