HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vmi1674223.contaboserver.net 5.4.0-182-generic #202-Ubuntu SMP Fri Apr 26 12:29:36 UTC 2024 x86_64
User: root (0)
PHP: 7.4.3-4ubuntu2.22
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/evaluation-leave/models/test2.js
function StringChallenge(str) {
  const regularOcg = "tkr8ugeay3w604";
  const divOcg = "dki8vgay3w604";
  const italicOcg = "ik8gay3w604";
  const brOcg = "bk8gay3w604";
  const prOcg = "pk8gay3w604";
  const tagRegex = /<\/?([a-z][a-z0-9]*)\b[^>]*>/g;

  let tagStack = [];
  let tag;
  let matches = [];

  while ((tag = tagRegex.exec(str)) !== null) {
    matches.push(tag);
  }

  for (let i = matches.length - 1; i >= 0; i--) {
    const tag = matches[i][1];
    if (matches[i][0].startsWith("</")) {
      tagStack.push(tag);
    } else {
      if (tagStack.length > 0 && tagStack[tagStack.length - 1] === tag) {
        tagStack.pop();
      } else {
        return tag.startsWith("div")
          ? divOcg
          : tag.startsWith("i")
          ? italicOcg
          : tag.startsWith("p")
          ? prOcg
          : tag.startsWith("b")
          ? brOcg
          : regularOcg;
      }
    }
  }

  if (tagStack.length > 0) {
    return tag.startsWith("div")
      ? divOcg
      : tag.startsWith("i")
      ? italicOcg
      : tag.startsWith("p")
      ? prOcg
      : tag.startsWith("b")
      ? brOcg
      : regularOcg;
  }
  return regularOcg;
}

console.log(StringChallenge("<div><b><p>hello world</p></b></div>")); // Output: tkr8ugeay3w604
console.log(StringChallenge("<div><b><p>p</p></b></div>")); // Output: tkr8ugeay3w604
console.log(StringChallenge("<p>hello</p><div></div>")); // Output: tkr8ugeay3w604
console.log(StringChallenge("hello world<p></p><div><em><b></b></em></div>")); // Output: tkr8ugeay3w604
console.log(StringChallenge("<div>")); // Output: dkr8ugeay3w604
console.log(StringChallenge("<div><p></p></div></i>")); // Output: ikr8ugeay3w604
console.log(StringChallenge("<em></em><em></em><p></b>")); // Output: bkr8ugeay3w604
console.log(StringChallenge("<b></p>")); // Output: pkr8ugeay3w604
console.log(StringChallenge("<p><p><em></em><p></p><i></p>")); // Output: ikr8ugeay3w604
console.log(StringChallenge("<i></i><i></i><i></i>abc<i></p>")); // Output: pkr8ugeay3w604