FED54. 计时器
描述
实现一个打点计时器,要求HTML/CSS/JavaScript 解法, 执行用时: 856ms, 内存消耗: 77880KB, 提交时间: 2020-11-23
{"css":"","js":"function count(start, end) {\n console.log(start++) \n var timer = setInterval(function(){\n if(start <= end) {\n console.log(start++)\n }else {\n clearInterval(timer)\n }\n },100)\n return {cancel:function () {\n clearInterval(timer)\n }}\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 858ms, 内存消耗: 77772KB, 提交时间: 2020-11-23
{"css":"","js":"function count(start, end) {\n //立即输出第一个值\n console.log(start++);\n var timer = setInterval(function(){\n if(start <= end){\n console.log(start++);\n }else{\n clearInterval(timer);\n }\n },100);\n //返回一个对象\n return {\n cancel : function(){\n clearInterval(timer);\n }\n };\n } ","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 860ms, 内存消耗: 77772KB, 提交时间: 2021-03-15
{"css":"","js":"function count(start, end) {\n console.log(start++);\n var timer = setInterval(function(){\n if(start <= end){\n console.log(start++)\n }else{\n clearInterval(timer)\n }\n },100);\n return {\n cancel:function(){\n clearInterval(timer)\n }\n }\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 861ms, 内存消耗: 77772KB, 提交时间: 2021-06-26
{"css":"","js":"function count(start, end) {\n console.log(start);\n let timer = setInterval(()=>{\n if(start<end){\n console.log(++start);\n }else{\n clearInterval(timer);\n }\n },1000)\n return {\n cancel(){\n clearInterval(timer);\n }\n }\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 863ms, 内存消耗: 77792KB, 提交时间: 2021-03-15
{"css":"","js":"function count(start, end) {\n console.log(start++);\n let index=start\n let timer=setInterval(()=>{if(index<=end){console.log(index++)}},100)\n return {cancel:()=>{clearInterval(timer)}}\n}","html":"","libs":[]}