Uncaught TypeError:无法读取未定义调试的属性“ length”

时间:2019-07-24 13:05:58

标签: javascript

我有这段代码...我认为一切都很好,但是当我运行控制台时。它给了我这个错误:

  

未捕获的TypeError:无法读取函数3上未定义的属性“ length”。

此外,我们不允许使用内置功能,例如slicesplicefilterforEach,这就是我自定义某些功能的原因。

function check_includes(array_1, n) {
       for (p in array_1) {
           if (array_1[p] === n) {
               return true
           }
       }
       return false
   }
   function to_lower_case(tmp_mah_string) {
       let tmp_mah_final_string = ""
       for (let i in tmp_mah_string) {
           if (tmp_mah_string.charCodeAt(i) >= 65 && tmp_mah_string.charCodeAt(i) <= 90) {
               tmp_mah_final_string += String.fromCharCode(tmp_mah_string.charCodeAt(i) + 32)
           } else {
               tmp_mah_final_string += tmp_mah_string[i]
           }
       }
       return tmp_mah_final_string;
   }

   function slow_sort(mah_array) {
       for (j in mah_array) {
           for (let i = 0; i < mah_array.length - 1; i++) {
               if (mah_array[i] > mah_array[i + 1]) {
                   let tmp_placeholder = mah_array[i]
                   mah_array[i] = mah_array[i + 1]
                   mah_array[i + 1] = tmp_placeholder
               }
           }
       }
       return mah_array
   }
       function_three(["u", "f", "3", "7"], [2, 1, 4, "r"], [9, "f", 8, "t", 3, "r", 4]);

       function function_three(array_1, array_2, array_3) {
           let repeated_elements = []
           for (let i = 0; i < array_1.length; i++) {
               if (check_includes(array_2, array_1[i])) {
                   repeated_elements[repeated_elements.length] = array_1[i]
               }
           }
           for (let i = 0; i < array_2.length; i++) {
               if (check_includes(array_3, array_2[i])) {
                   repeated_elements[repeated_elements.length] = array_2[i]
               }
           }
           for (let i = 0; i < array_3.length; i++) {
               if (check_includes(array_3, array_1[i])) {
                   repeated_elements[repeated_elements.length] = array_1[i]
               }
           }
           for (let i in repeated_elements) {
               if (typeof (repeated_elements[i]) == 'string') {
                   repeated_elements[i] = to_lower_case(repeated_elements[i])
               }
           }
           let array_num = []
           let array_str = []
           for (let i in repeated_elements) {
               if (typeof (repeated_elements[i]) == 'string') {
                   array_str[array_str.length] = repeated_elements[i]
               } else {
                   array_num[array_num.length] = repeated_elements[i]
               }
           }
           let answer_array = []
           for (let i in array_num) {
               answer_array[i] = array_num[i]
           }
           for (let i = 0; i < array_str.length; i++) {
               answer_array[i + array_num.length] = array_str[i]
           }
           return slow_sort(answer_array);
       }

       console.log(function_three()); 

所指示的预期输出将是:编写一个函数,该函数接受3个数组并以升序返回一串重复的元素。返回所有小写字母。

E.G。函数([[1,2,3,’d'],[5,3,0,‘a’],[‘A’,’d’,9]返回“ 3,d”

错误出现在for (let i = 0; i < array_1.length; i++) {

对于如何调试此代码感到困惑。

0 个答案:

没有答案