我有一個字符串,像這樣的數組:檢查數組的字符串顯示爲另一個陣列的字符串的一部分
var inputArray= [
"Bob Johnson goes to the zoo",
"Timothy Smith likes to eat ice-cream",
"Jenny wants to play with her friends",
"There is no one in the room to play with Timothy",
"Jeremy Jones has been sleeping all day"
];
...和名稱的另一個數組,像這樣:
var names = [
"bob johnson",
"bob",
"timothy smith",
"timothy",
"jenny sanderson",
"jenny",
"jeremy jones",
"jeremy"
];
...我想要做的是檢查inputArray中的每個字符串,看它們是否包含names數組中的任何名稱。
只要找到名稱匹配,它應該做兩件事情:
按名稱的answerKey陣列像這樣:
VAR answerKey = [ 「鮑勃」, 「蒂莫西「, 」jenny「, 」timothy「, 」jeremy「 ];
和2.推動名稱替換爲'?'的字符串。另一個數組(輸出),像這樣:
var output = [
"? goes to the zoo",
"? likes to eat ice-cream",
"? wants to play with her friends",
"There is no one in the room to play with ?",
"? has been sleeping all day"
];
我熟悉檢查字符串中的子串而不是當子是一個數組和字符串反對進行檢查是另一個。任何幫助將是非常讚賞:))
看起來像家庭工作! –