美文网首页
js 字符串字符匹配

js 字符串字符匹配

作者: 泪滴在琴上 | 来源:发表于2024-02-14 18:15 被阅读0次

描述
判断短字符串S中的所有字符是否在长字符串T中全部出现。
输入描述:
输入两个字符串。第一个为短字符串,第二个为长字符串。两个字符串均由小写字母组成。

输出描述:
如果短字符串的所有字符均在长字符串中出现过,则输出字符串"true"。否则输出字符串"false"。
输入:
bc
abc
输出:
true
说明:
其中abc含有bc,输出"true"

let arr = []
    while(line = await readline()){
       arr.push(line)
    }
    let firstArr = arr[0].split('')
    let count = new Array(arr[0].length).fill(0)
    firstArr.map((item,index)=>{
        let reg = new RegExp(item,'g')
        let length = arr[1].match(reg)
        count[index] = length?length.length:0
    })
        console.log(!!Math.min(...count))

相关文章

网友评论

      本文标题:js 字符串字符匹配

      本文链接:https://www.haomeiwen.com/subject/hpcsadtx.html