列表

详情


JS17. 子字符串频次

描述

请补全JavaScript代码,该函数接受两个参数分别为字符串、子字符串,要求返回子字符串在字符串中出现的频次。

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 1687ms, 内存消耗: 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 _searchStrIndexOf = (str, target) => {\n                // 补全代码\n                var a = str.split(target)\n                return a.length-1\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1738ms, 内存消耗: 77812KB, 提交时间: 2021-12-06

{"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 _searchStrIndexOf = (str, target) => {\n                // 补全代码\n                let reg = new RegExp(target,'g');\n                return str.match(reg).length;\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1738ms, 内存消耗: 77916KB, 提交时间: 2022-01-01

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n\n<head>\n    <meta charset=\"UTF-8\">\n</head>\n\n<body>\n\n    <script>\n        const _searchStrIndexOf = (str, target) => {\n            // 补全代码\n            let count = 0\n            if (str.indexOf(target) !== -1) {\n                count++\n                if (str.indexOf(target), str.indexOf(target)) {\n                    count++\n                    if (str.indexOf(target), str.indexOf(target)) {\n                        count++\n                    }\n                }\n            }\n            return count\n        }\n    </script>\n</body>\n\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1740ms, 内存消耗: 77872KB, 提交时间: 2021-12-16

{"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 _searchStrIndexOf = (str, target) => {\n                // 补全代码\n                var p=str.indexOf(target);\n                var count=0;\n                while(p!=-1){\n                    count++;\n                    p=str.indexOf(target,p+1);\n                }\n                return count;\n            }\n        </script>\n    </body>\n</html>","libs":[]}

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

{"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 _searchStrIndexOf = (str, target) => {\n                // 补全代码\n                return str.split(target).length - 1\n            }\n        </script>\n    </body>\n</html>","libs":[]}

上一题