列表

详情


JS2. 文件扩展名

描述

请补全JavaScript代码,要求以字符串的形式返回文件名扩展名,文件名参数为"filename"。

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 1680ms, 内存消耗: 77816KB, 提交时间: 2022-02-10

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        \n        <script>\n            const _getExFilename = (filename) => {\n                // 补全代码\n               let index =filename.lastIndexOf('.');\n                return filename.slice(0,index)&&index!=-1?filename.slice(index):''\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1681ms, 内存消耗: 77812KB, 提交时间: 2022-02-09

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        \n        <script>\n            const _getExFilename = (filename) => {\n                // 补全代码\n                let index = filename.lastIndexOf('.')\n                return filename.slice(0,index) && index !== -1 ? filename.slice(index) : ''\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1686ms, 内存消耗: 77772KB, 提交时间: 2022-02-08

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        \n        <script>\n            const _getExFilename = (filename) => {\n                // 补全代码\n                const index= filename.lastIndexOf('.')\n                const name= filename.slice(index)\n                return name\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1703ms, 内存消耗: 77820KB, 提交时间: 2022-02-09

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        \n        <script>\n            const _getExFilename = (filename) => {\n                // 补全代码\n                const res = filename.split('.')\n                return '.'+res.pop()\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1736ms, 内存消耗: 77772KB, 提交时间: 2022-02-10

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        \n        <script>\n            const _getExFilename = (filename) => {\n                // 补全代码\n                var a=filename.split('.')\n                return '.'+a[a.length-1]\n            }\n        </script>\n    </body>\n</html>","libs":[]}

上一题