1

#yyds干货盘点# 前端歌谣的刷题之路-第九十题-子字符串频次

 1 year ago
source link: https://blog.51cto.com/u_14476028/5707334
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

#yyds干货盘点# 前端歌谣的刷题之路-第九十题-子字符串频次

精选 原创

前端歌谣 2022-09-23 16:49:21 ©著作权

文章标签 字符串 子字符串 html 文章分类 JavaScript 前端开发 阅读数173

我是歌谣 我有个兄弟 巅峰的时候排名c站总榜19 叫前端小歌谣 曾经我花了三年的时间创作了他 现在我要用五年的时间超越他 今天又是接近兄弟的一天人生难免坎坷 大不了从头再来 歌谣的意志是永恒的 放弃很容易 但是坚持一定很酷 本题目源自于牛客网 微信公众号前端小歌谣

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

#yyds干货盘点# 前端歌谣的刷题之路-第九十题-子字符串频次_html

编辑

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>字符串频次</title>
</head>
<body>
<!-- 请补全JavaScript代码,该函数接受两个参数分别为字符串、子字符串,要求返回子字符串在字符串中出现的频次。 -->
<!--
使用split分割(target为分割点)
有n个target返回的列表就会有n+1个元素
对列表取长度并且-1就会得到target的个数
-->
<script>const _searchStrIndexOf = (str, target) => {
// 补全代码

return str.split(target).length - 1</script>
</body>
</html>

使用split分割(target为分割点)有n个target返回的列表就会有n+1个元素

  对列表取长度并且-1就会得到target的个数


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK