{"id":8545,"date":"2021-08-13T22:35:37","date_gmt":"2021-08-13T19:35:37","guid":{"rendered":"https:\/\/elzero.org\/?p=8545"},"modified":"2022-08-07T07:06:45","modified_gmt":"2022-08-07T04:06:45","slug":"javascript-problems-solving-remove-duplicate-words","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/javascript-problems-solving-remove-duplicate-words\/","title":{"rendered":"Remove Duplicate Words From String"},"content":{"rendered":"<h3>\u0627\u0644\u062d\u0644 \u0627\u0644\u0645\u0648\u062c\u0648\u062f \u0641\u064a \u0627\u0644\u0641\u064a\u062f\u064a\u0648<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\nfunction removeDuplicateWordsFrom(sentence) {\r\n  let wordsList = sentence.split(\" \");\r\n  let result = [];\r\n  for (let i = 0; i < wordsList.length; i++) {\r\n    if (result.indexOf(wordsList[i]) === -1) {\r\n      result.push(wordsList[i]);\r\n    }\r\n  }\r\n  return result.join(\" \");\r\n}\r\n\r\nconsole.log(removeDuplicateWordsFrom(\"Hello Elzero Web Web Hello School\"));\r\n\/\/ Hello Elzero Web School\r\n\r\n<\/script>\r\n\r\n<h3>\u0627\u0644\u062d\u0644 \u0627\u0644\u062b\u0627\u0646\u064a \u0627\u0644\u0645\u0648\u062c\u0648\u062f \u0641\u064a \u0627\u0644\u0641\u064a\u062f\u064a\u0648<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\nfunction removeDuplicateWordsFrom(sentence) {\r\n  let wordsList = sentence.split(\" \");\r\n  console.log(wordsList);\r\n  let newSet = new Set(wordsList);\r\n  console.log(newSet);\r\n  \/\/ let arrayFromSet = [...newSet];\r\n  let arrayFromSet = Array.from(newSet);\r\n  console.log(arrayFromSet);\r\n  let joinWords = arrayFromSet.join(\" \");\r\n  console.log(joinWords);\r\n  return joinWords;\r\n}\r\n\r\nconsole.log(removeDuplicateWordsFrom(\"Hello Elzero Web Web Hello School\"));\r\n\/\/ Hello Elzero Web School\r\n<\/script>\r\n\r\n<h3>\u0627\u0644\u062d\u0644 \u0627\u0644\u062b\u0627\u0646\u064a \u0628\u0633\u0637\u0631 \u0648\u0627\u062d\u062f \u0641\u0642\u0637<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\nfunction removeDuplicateWordsFrom(sentence) {\r\n  return [...new Set(sentence.split(\" \"))].join(\" \");\r\n}\r\n\r\nconsole.log(removeDuplicateWordsFrom(\"Hello Elzero Web Web Hello School\"));\r\n\/\/ Hello Elzero Web School\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>Remove Duplicate Words From String<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1337],"tags":[],"class_list":["post-8545","post","type-post","status-publish","format-standard","hentry","category-problems-solving"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/8545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=8545"}],"version-history":[{"count":2,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/8545\/revisions"}],"predecessor-version":[{"id":8547,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/8545\/revisions\/8547"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=8545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=8545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=8545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}