有一个字符串let a=“hello, are you hello kitty”,定义一个函数highlight(a,“hello”),传这两个参数,将字符串a中的hello变红,请手写这个函数。
你们用什么规范代码的?
function changeColor(longStr, str) {
return longStr.split(str).join(`<span color='red'>${str}<span>`)
}
const str1 = changeColor('hello world, hello world, hello', 'hello')
document.innerHTML = str1