0020【Edabit ★☆☆☆☆☆】Buggy Code (Part 5)

编程入门 行业动态 更新时间:2024-10-19 10:18:44

0020【<a href=https://www.elefans.com/category/jswz/34/1666502.html style=Edabit ★☆☆☆☆☆】Buggy Code (Part 5)"/>

0020【Edabit ★☆☆☆☆☆】Buggy Code (Part 5)

0020【Edabit ★☆☆☆☆☆】Buggy Code (Part 5)

bugs data_structures loops numbers

Instructions

Jim created an infinite loop! Help him by fixing the code in the code tab to pass this challenge. Look at the examples below to get an idea of what the function should do.

Examples
printArray(1) // [1]
printArray(3) // [1, 2, 3]
printArray(6) // [1, 2, 3, 4, 5, 6]
Notes
  • READ EVERY WORD CAREFULLY, CHARACTER BY CHARACTER!
  • Don’t overthink this challenge; it’s not supposed to be hard.
Solutions
function printArray(number) {var newArray = [];for(var i = 1; i <= number; i++) { // 添加 i++newArray.push(i);}return newArray;
}
TestCases
let Test = (function(){return {assertSimilar:function(actual,expected){if(actual.length != expected.length){throw new Error(`length is not equals, ${actual},${expected}`);}for(let a of actual){if(!expected.includes(a)){throw new Error(`missing ${a}`);}}}}
})();Test.assertSimilar(printArray(1), [1])
Test.assertSimilar(printArray(2), [1,2])
Test.assertSimilar(printArray(3), [1,2,3])
Test.assertSimilar(printArray(4), [1,2,3,4])
Test.assertSimilar(printArray(5), [1,2,3,4,5])
Test.assertSimilar(printArray(6), [1,2,3,4,5,6])
Test.assertSimilar(printArray(7), [1,2,3,4,5,6,7])
Test.assertSimilar(printArray(8), [1,2,3,4,5,6,7,8])
Test.assertSimilar(printArray(9), [1,2,3,4,5,6,7,8,9])
Test.assertSimilar(printArray(10), [1,2,3,4,5,6,7,8,9,10])

更多推荐

0020【Edabit ★☆☆☆☆☆】Buggy Code (Part 5)

本文发布于:2023-12-04 20:00:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1662061.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Edabit   Buggy   Part   Code

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!