Viết hàm replaceChar(str, arr, [char]): thay thế tất cả ký tự của str không có trong mảng arr bằng char (mặc định '*').
Ví dụ
const arr = ['a', 'e', 'i', 'o', 'u']; const text = 'I looked for Mary and Samantha at the bus station.'; const replaceChar = (str, arr, char = '*') => { const replacedString = str.split("").map(word => { return arr.includes(word) ? word : char; }).join(""); return replacedString; }; console.log(replaceChar(text, arr));Kết quả
Đầu ra console:
***oo*e***o***a***a****a*a***a*a****e**u****a*io**