আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা একটি স্ট্রিং এবং স্ট্রিংগুলির একটি অ্যারে নেয়৷
আমাদের ফাংশনটি একটি নতুন স্ট্রিং ফিরিয়ে আনবে, যেখানে অ্যারেতে উপস্থিত স্ট্রিংয়ের শব্দের সমস্ত ঘটনা একটি হোয়াইটস্পেস দ্বারা প্রতিস্থাপিত হবে৷
এই সমস্যা সমাধানের জন্য আমাদের ফাংশন String.prototype.replace() পদ্ধতি ব্যবহার করা উচিত।
উদাহরণ
এর জন্য কোড হবে −
var excludeWords = ["A", "ABOUT", "ABOVE", "ACROSS", "ALL", "ALONG", "AM", "AN", "AND", "ANY", "ASK", "AT", "AWAY", "CAN", "DID", "DIDN'T", "DO", "DON'T", "FOR", "FROM", "HAD", "HAS", "HER", "HIS", "IN", "INTO", "IS", "IT", "NONE", "NOT", "OF", "ON", "One", "OUT", "SO", "SOME", "THAT", "THE", "THEIR", "THERE", "THEY", "THESE", "THIS", "TO", "TWIT", "WAS", "WERE", "WEREN'T", "WHICH", "WILL", "WITH", "WHAT", "WHEN", "WHY"]; var sentence = "The first solution does not work for any UTF-8 alphaben. I have managed to create function which do not use RegExp and use good UTF-8 support in JavaScript engine. The idea is simple if symbol is equal in uppercase and lowercase it is special character. The only exception is made for whitespace."; const removeExcludedWords = (str, words) => { let sentence = ''; const regex = new RegExp(`\\b(${words.join('|')})\\b`, 'gi'); sentence = str.replace(regex, ""); return sentence; }; console.log(removeExcludedWords(sentence, excludeWords));
আউটপুট
কনসোলে আউটপুট -
first solution does work UTF-8 alphaben. I have managed create function use RegExp use good UTF-8 support JavaScript engine. idea simple if symbol equal uppercase lowercase special character. only exception made whitespace.