拉丁字母两个小写字母或相邻位置的大写字母 javascript空数组,尽管调用了push方法

问题描述

我正在尝试检查给定的字符串是否仅包含拉丁字母,并且相邻位置中是否没有两个大写字母和两个小写字母。 我是从这个计划开始的:
1.检查字符串是否仅包含拉丁字母(如果声明),如果是:
2.检查是否为upperCase(for循环)
3。将所有.indexof数字放入另一个数组[](用于循环)
4.使用.map到此数组以查找字母索引之间的差异
4.if差等于1-表示两个大写字母彼此相邻。
4a。与小写字母相同。

我的问题始于.push的point3。此方法不适用于我。 Console.log返回空字符串...
我尝试了.push,.concat,循环-什么都没有。
因为textContent显示了大写字母的索引(很好),所以我尝试从t101ans.textContent中获取值,但是没有成功,数组仍然为空。
我在做什么错了?

const task101 = () => {
  const task101in = document.querySelector("#task101in").value;
  const t101ans = document.querySelector("#task101ans");
  const another = [];
  //if length of string is not the same as length of latin letters
  if ((task101in.match(/[a-zA-Z]/g) || "").length != task101in.length) {
    t101ans.textContent = `Non Latin letters,try again`;
  } else {
    //looking for uppercase letters
    for (let i = 0; i < task101in.length; i++) {
      //check index of uppercase
      const indexnum = task101in.indexOf(task101in[i].match(/[A-Z]/g));
      //trying to push indexof numbers to an array
      for (let y = 0; y <= indexnum.length; y++) {
        // const another = [];
        another = another.push(indexnum)
        return another
      }
      t101ans.textContent += indexnum
    }
  }
};
document.querySelector("#task101").addEventListener("click",task101);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)