JS6. 判断版本
描述
请补全JavaScript代码,该函数接收两个参数分别为旧版本、新版本,当新版本高于旧版本时表明需要更新,返回true,否则返回false。HTML/CSS/JavaScript 解法, 执行用时: 1687ms, 内存消耗: 77820KB, 提交时间: 2022-02-09
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n const _shouldUpdate = (oldVersion, newVersion) => {\n // 补全代码\n let newArr = newVersion.split(\".\")\n let oldArr = oldVersion.split(\".\")\n let flag = false\n for(let i=0;i<newArr.length;i++){\n document.body.innerText+=(Number(newArr[i])>Number(oldArr[i]))\n if(Number(newArr[i])>Number(oldArr[i])){\n flag = true\n }\n }\n return flag\n }\n _shouldUpdate('9.0.1','9.1.0');\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1697ms, 内存消耗: 77816KB, 提交时间: 2022-02-10
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n const _shouldUpdate = (oldVersion, newVersion) => {\n // 补全代码\n let oldversion = parseInt(oldVersion.split('.').join(''))\n let newversion = parseInt(newVersion.split('.').join(''))\n return newversion > oldversion\n }\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1747ms, 内存消耗: 77768KB, 提交时间: 2022-01-22
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n const _shouldUpdate = (oldVersion, newVersion) => {\n // 补全代码\n var olds = Number(oldVersion.split('.').join(''))\n var news = Number(newVersion.split('.').join(''))\n if(news>olds){\n return true\n }else {\n return false\n }\n }\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1748ms, 内存消耗: 77776KB, 提交时间: 2021-12-05
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n const _shouldUpdate = (oldVersion, newVersion) => {\n // 刀根火种\n let a = oldVersion.split('.')\n\t\t\t let b = newVersion.split('.')\n\t\t\t \n\t\t\t let num1 =\"\";let num2 =\"\";let stsus=false;\n\t\t\t for(var i=0;i<a.length;i++){\n\t\t\t\t\t num1+= a[i]\n\t\t\t }\n\t\t\t \n\t\t\t for(var j=0;j<b.length;j++){\n\t\t\t \t\t num2+= b[j]\n\t\t\t }\n\t\t\t \n\t\t\t if (num1==num2) {\n\t\t\t \t alert('不足要跟新')\n\t\t\t } else if(num1 > num2){\n\t\t\t \t\tstsus = false\n\t\t\t } if(num1 < num2){\n\t\t\t \t stsus= true\n\t\t\t } \n\t\t\t\n\t\t\t return stsus;\n\t\t\t \n }\n\t\t\t\n\t\tconsole.log( _shouldUpdate(\"1.3.2\",\"0.3.3\"))\n </script>\n </body>\n</html>\n\n","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1749ms, 内存消耗: 77856KB, 提交时间: 2021-12-27
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n const _shouldUpdate = (oldVersion, newVersion) => {\n // 补全代码\n const getVerNum = (v) => {\n return v.replace(/\\./g, '')\n }\n return getVerNum(newVersion) > getVerNum(oldVersion)\n }\n </script>\n </body>\n</html>","libs":[]}