对于如何返回包含井号'#'并提及'@'出现次数的对象,我有些困惑
我一直在尝试结合使用filter和map方法,但没有运气
功能hashtagandmentions(单词){
E.g. "The football was great @england #winning #goals"
The function should return an object describing the number of hashtags and mentions found:
答案 0 :(得分:0)
只需尝试:
const output = {
hashtags: (str.match(/#\w+/g) || []).length,
mentions: (str.match(/@\w+/g) || []).length,
}