JavaScript Arrays delete duplicate words or characters(if only characters are entered. Not to delete from 1...












0














Enter : Samsung , Enter again : Samsung , Enter again: Tomas, Enter again: sass, Enter again : sass, Enter again: b, Enter again : b, Enter again : bb, Enter again : bb........



And to display the following :
With removeDuplicateUsingSet: Samsung, Tomas, sass, b, bb
Without the function : Samsung,Samsung,Tomas,sass,sass,b,b,bb,bb
and the loop to stop when you type stop.....



function removeDuplicateUsingSet(arr){
let unique_array = Array.from(new Set(arr))
return unique_array}

var inputs =;
var alreadyEntered = false;
while (!alreadyEntered)
{
var input = prompt("Enter items until you enter it twice");

for (var i=0;i<inputs.length;i++) {
if (inputs[i] == input)
{
alert("Already entered!");
alreadyEntered = true;
break;
}

}
inputs.push(input);
}



alert("With removeDuplicateUsingSet function : " + "n" +
removeDuplicateUsingSet(inputs) + "n" + "Without: " + "n" + inputs);


Now this code have break loop and i don't know how to fix it....
Tried doing this next thing :



function removeDuplicateUsingSet(arr){
let unique_array = Array.from(new Set(arr))
return unique_array
}

var array = ;
var stored = ;
while(array !== 'stop')
{
stored.push(prompt('what are your fav books ? '));
array = prompt('If you would like to continue enter any key otherwise enter or type stop');

// document.write(stored + " , ");
console.log(removeDuplicateUsingSet(array) + "n___________");
}
alert("With removeDuplicateUsingSet function : " + "n" +
removeDuplicateUsingSet(array) + "n" + "Without: " + "n" + stored);


but also not what i have been wanted....
It keeps removing all of the duplicate characters (ex. "Samsung" displays it SAMUNG,where i want to remove if there are entered 2 same elements(items)
Please help me.
Thanks in advance.










share|improve this question



























    0














    Enter : Samsung , Enter again : Samsung , Enter again: Tomas, Enter again: sass, Enter again : sass, Enter again: b, Enter again : b, Enter again : bb, Enter again : bb........



    And to display the following :
    With removeDuplicateUsingSet: Samsung, Tomas, sass, b, bb
    Without the function : Samsung,Samsung,Tomas,sass,sass,b,b,bb,bb
    and the loop to stop when you type stop.....



    function removeDuplicateUsingSet(arr){
    let unique_array = Array.from(new Set(arr))
    return unique_array}

    var inputs =;
    var alreadyEntered = false;
    while (!alreadyEntered)
    {
    var input = prompt("Enter items until you enter it twice");

    for (var i=0;i<inputs.length;i++) {
    if (inputs[i] == input)
    {
    alert("Already entered!");
    alreadyEntered = true;
    break;
    }

    }
    inputs.push(input);
    }



    alert("With removeDuplicateUsingSet function : " + "n" +
    removeDuplicateUsingSet(inputs) + "n" + "Without: " + "n" + inputs);


    Now this code have break loop and i don't know how to fix it....
    Tried doing this next thing :



    function removeDuplicateUsingSet(arr){
    let unique_array = Array.from(new Set(arr))
    return unique_array
    }

    var array = ;
    var stored = ;
    while(array !== 'stop')
    {
    stored.push(prompt('what are your fav books ? '));
    array = prompt('If you would like to continue enter any key otherwise enter or type stop');

    // document.write(stored + " , ");
    console.log(removeDuplicateUsingSet(array) + "n___________");
    }
    alert("With removeDuplicateUsingSet function : " + "n" +
    removeDuplicateUsingSet(array) + "n" + "Without: " + "n" + stored);


    but also not what i have been wanted....
    It keeps removing all of the duplicate characters (ex. "Samsung" displays it SAMUNG,where i want to remove if there are entered 2 same elements(items)
    Please help me.
    Thanks in advance.










    share|improve this question

























      0












      0








      0







      Enter : Samsung , Enter again : Samsung , Enter again: Tomas, Enter again: sass, Enter again : sass, Enter again: b, Enter again : b, Enter again : bb, Enter again : bb........



      And to display the following :
      With removeDuplicateUsingSet: Samsung, Tomas, sass, b, bb
      Without the function : Samsung,Samsung,Tomas,sass,sass,b,b,bb,bb
      and the loop to stop when you type stop.....



      function removeDuplicateUsingSet(arr){
      let unique_array = Array.from(new Set(arr))
      return unique_array}

      var inputs =;
      var alreadyEntered = false;
      while (!alreadyEntered)
      {
      var input = prompt("Enter items until you enter it twice");

      for (var i=0;i<inputs.length;i++) {
      if (inputs[i] == input)
      {
      alert("Already entered!");
      alreadyEntered = true;
      break;
      }

      }
      inputs.push(input);
      }



      alert("With removeDuplicateUsingSet function : " + "n" +
      removeDuplicateUsingSet(inputs) + "n" + "Without: " + "n" + inputs);


      Now this code have break loop and i don't know how to fix it....
      Tried doing this next thing :



      function removeDuplicateUsingSet(arr){
      let unique_array = Array.from(new Set(arr))
      return unique_array
      }

      var array = ;
      var stored = ;
      while(array !== 'stop')
      {
      stored.push(prompt('what are your fav books ? '));
      array = prompt('If you would like to continue enter any key otherwise enter or type stop');

      // document.write(stored + " , ");
      console.log(removeDuplicateUsingSet(array) + "n___________");
      }
      alert("With removeDuplicateUsingSet function : " + "n" +
      removeDuplicateUsingSet(array) + "n" + "Without: " + "n" + stored);


      but also not what i have been wanted....
      It keeps removing all of the duplicate characters (ex. "Samsung" displays it SAMUNG,where i want to remove if there are entered 2 same elements(items)
      Please help me.
      Thanks in advance.










      share|improve this question













      Enter : Samsung , Enter again : Samsung , Enter again: Tomas, Enter again: sass, Enter again : sass, Enter again: b, Enter again : b, Enter again : bb, Enter again : bb........



      And to display the following :
      With removeDuplicateUsingSet: Samsung, Tomas, sass, b, bb
      Without the function : Samsung,Samsung,Tomas,sass,sass,b,b,bb,bb
      and the loop to stop when you type stop.....



      function removeDuplicateUsingSet(arr){
      let unique_array = Array.from(new Set(arr))
      return unique_array}

      var inputs =;
      var alreadyEntered = false;
      while (!alreadyEntered)
      {
      var input = prompt("Enter items until you enter it twice");

      for (var i=0;i<inputs.length;i++) {
      if (inputs[i] == input)
      {
      alert("Already entered!");
      alreadyEntered = true;
      break;
      }

      }
      inputs.push(input);
      }



      alert("With removeDuplicateUsingSet function : " + "n" +
      removeDuplicateUsingSet(inputs) + "n" + "Without: " + "n" + inputs);


      Now this code have break loop and i don't know how to fix it....
      Tried doing this next thing :



      function removeDuplicateUsingSet(arr){
      let unique_array = Array.from(new Set(arr))
      return unique_array
      }

      var array = ;
      var stored = ;
      while(array !== 'stop')
      {
      stored.push(prompt('what are your fav books ? '));
      array = prompt('If you would like to continue enter any key otherwise enter or type stop');

      // document.write(stored + " , ");
      console.log(removeDuplicateUsingSet(array) + "n___________");
      }
      alert("With removeDuplicateUsingSet function : " + "n" +
      removeDuplicateUsingSet(array) + "n" + "Without: " + "n" + stored);


      but also not what i have been wanted....
      It keeps removing all of the duplicate characters (ex. "Samsung" displays it SAMUNG,where i want to remove if there are entered 2 same elements(items)
      Please help me.
      Thanks in advance.







      javascript arrays loops continue






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 at 3:06









      Tomas Jovanov

      31




      31
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Is this your desired output?






          function removeDuplicateUsingSet(arr) {
          let unique_array = Array.from(new Set(arr))
          return unique_array
          }

          var inputs = ;
          while (true) {
          var input = prompt("Enter items until you enter it twice");
          if (input == 'stop') break;

          inputs.push(input);
          }

          alert("With removeDuplicateUsingSet function : " + "n" + removeDuplicateUsingSet(inputs) +
          "n" + "Without: " + "n" + inputs);








          share|improve this answer























          • Yup :) i`ll compare and see what i did wrong :D huge thanks <3 ---.... omg i see now that i was using while instead of if .... :)
            – Tomas Jovanov
            Nov 16 at 6:18












          • you still have to use while for user inputs. What you did wrong is: as user inputs, you tried to compare the array immediately. You already have the function to remove duplicates so all you have to do is just push the input into the array.
            – ACD
            Nov 16 at 6:33










          • yeah i know now :D i have skipped some classes when i was in college and now im paying for them :D but luckily im at learning academy now and the teacher also explained what i have done wrong :D so thanks for the support and the quick answer, you kinda saved me there, and then i had the opportunity to learn what was right and what was wrong :D its much easier to see when you compare fully functional code with the one ive created :D
            – Tomas Jovanov
            Dec 14 at 22:06











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330849%2fjavascript-arrays-delete-duplicate-words-or-charactersif-only-characters-are-en%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Is this your desired output?






          function removeDuplicateUsingSet(arr) {
          let unique_array = Array.from(new Set(arr))
          return unique_array
          }

          var inputs = ;
          while (true) {
          var input = prompt("Enter items until you enter it twice");
          if (input == 'stop') break;

          inputs.push(input);
          }

          alert("With removeDuplicateUsingSet function : " + "n" + removeDuplicateUsingSet(inputs) +
          "n" + "Without: " + "n" + inputs);








          share|improve this answer























          • Yup :) i`ll compare and see what i did wrong :D huge thanks <3 ---.... omg i see now that i was using while instead of if .... :)
            – Tomas Jovanov
            Nov 16 at 6:18












          • you still have to use while for user inputs. What you did wrong is: as user inputs, you tried to compare the array immediately. You already have the function to remove duplicates so all you have to do is just push the input into the array.
            – ACD
            Nov 16 at 6:33










          • yeah i know now :D i have skipped some classes when i was in college and now im paying for them :D but luckily im at learning academy now and the teacher also explained what i have done wrong :D so thanks for the support and the quick answer, you kinda saved me there, and then i had the opportunity to learn what was right and what was wrong :D its much easier to see when you compare fully functional code with the one ive created :D
            – Tomas Jovanov
            Dec 14 at 22:06
















          0














          Is this your desired output?






          function removeDuplicateUsingSet(arr) {
          let unique_array = Array.from(new Set(arr))
          return unique_array
          }

          var inputs = ;
          while (true) {
          var input = prompt("Enter items until you enter it twice");
          if (input == 'stop') break;

          inputs.push(input);
          }

          alert("With removeDuplicateUsingSet function : " + "n" + removeDuplicateUsingSet(inputs) +
          "n" + "Without: " + "n" + inputs);








          share|improve this answer























          • Yup :) i`ll compare and see what i did wrong :D huge thanks <3 ---.... omg i see now that i was using while instead of if .... :)
            – Tomas Jovanov
            Nov 16 at 6:18












          • you still have to use while for user inputs. What you did wrong is: as user inputs, you tried to compare the array immediately. You already have the function to remove duplicates so all you have to do is just push the input into the array.
            – ACD
            Nov 16 at 6:33










          • yeah i know now :D i have skipped some classes when i was in college and now im paying for them :D but luckily im at learning academy now and the teacher also explained what i have done wrong :D so thanks for the support and the quick answer, you kinda saved me there, and then i had the opportunity to learn what was right and what was wrong :D its much easier to see when you compare fully functional code with the one ive created :D
            – Tomas Jovanov
            Dec 14 at 22:06














          0












          0








          0






          Is this your desired output?






          function removeDuplicateUsingSet(arr) {
          let unique_array = Array.from(new Set(arr))
          return unique_array
          }

          var inputs = ;
          while (true) {
          var input = prompt("Enter items until you enter it twice");
          if (input == 'stop') break;

          inputs.push(input);
          }

          alert("With removeDuplicateUsingSet function : " + "n" + removeDuplicateUsingSet(inputs) +
          "n" + "Without: " + "n" + inputs);








          share|improve this answer














          Is this your desired output?






          function removeDuplicateUsingSet(arr) {
          let unique_array = Array.from(new Set(arr))
          return unique_array
          }

          var inputs = ;
          while (true) {
          var input = prompt("Enter items until you enter it twice");
          if (input == 'stop') break;

          inputs.push(input);
          }

          alert("With removeDuplicateUsingSet function : " + "n" + removeDuplicateUsingSet(inputs) +
          "n" + "Without: " + "n" + inputs);








          function removeDuplicateUsingSet(arr) {
          let unique_array = Array.from(new Set(arr))
          return unique_array
          }

          var inputs = ;
          while (true) {
          var input = prompt("Enter items until you enter it twice");
          if (input == 'stop') break;

          inputs.push(input);
          }

          alert("With removeDuplicateUsingSet function : " + "n" + removeDuplicateUsingSet(inputs) +
          "n" + "Without: " + "n" + inputs);





          function removeDuplicateUsingSet(arr) {
          let unique_array = Array.from(new Set(arr))
          return unique_array
          }

          var inputs = ;
          while (true) {
          var input = prompt("Enter items until you enter it twice");
          if (input == 'stop') break;

          inputs.push(input);
          }

          alert("With removeDuplicateUsingSet function : " + "n" + removeDuplicateUsingSet(inputs) +
          "n" + "Without: " + "n" + inputs);






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 16 at 6:31

























          answered Nov 16 at 3:27









          ACD

          854111




          854111












          • Yup :) i`ll compare and see what i did wrong :D huge thanks <3 ---.... omg i see now that i was using while instead of if .... :)
            – Tomas Jovanov
            Nov 16 at 6:18












          • you still have to use while for user inputs. What you did wrong is: as user inputs, you tried to compare the array immediately. You already have the function to remove duplicates so all you have to do is just push the input into the array.
            – ACD
            Nov 16 at 6:33










          • yeah i know now :D i have skipped some classes when i was in college and now im paying for them :D but luckily im at learning academy now and the teacher also explained what i have done wrong :D so thanks for the support and the quick answer, you kinda saved me there, and then i had the opportunity to learn what was right and what was wrong :D its much easier to see when you compare fully functional code with the one ive created :D
            – Tomas Jovanov
            Dec 14 at 22:06


















          • Yup :) i`ll compare and see what i did wrong :D huge thanks <3 ---.... omg i see now that i was using while instead of if .... :)
            – Tomas Jovanov
            Nov 16 at 6:18












          • you still have to use while for user inputs. What you did wrong is: as user inputs, you tried to compare the array immediately. You already have the function to remove duplicates so all you have to do is just push the input into the array.
            – ACD
            Nov 16 at 6:33










          • yeah i know now :D i have skipped some classes when i was in college and now im paying for them :D but luckily im at learning academy now and the teacher also explained what i have done wrong :D so thanks for the support and the quick answer, you kinda saved me there, and then i had the opportunity to learn what was right and what was wrong :D its much easier to see when you compare fully functional code with the one ive created :D
            – Tomas Jovanov
            Dec 14 at 22:06
















          Yup :) i`ll compare and see what i did wrong :D huge thanks <3 ---.... omg i see now that i was using while instead of if .... :)
          – Tomas Jovanov
          Nov 16 at 6:18






          Yup :) i`ll compare and see what i did wrong :D huge thanks <3 ---.... omg i see now that i was using while instead of if .... :)
          – Tomas Jovanov
          Nov 16 at 6:18














          you still have to use while for user inputs. What you did wrong is: as user inputs, you tried to compare the array immediately. You already have the function to remove duplicates so all you have to do is just push the input into the array.
          – ACD
          Nov 16 at 6:33




          you still have to use while for user inputs. What you did wrong is: as user inputs, you tried to compare the array immediately. You already have the function to remove duplicates so all you have to do is just push the input into the array.
          – ACD
          Nov 16 at 6:33












          yeah i know now :D i have skipped some classes when i was in college and now im paying for them :D but luckily im at learning academy now and the teacher also explained what i have done wrong :D so thanks for the support and the quick answer, you kinda saved me there, and then i had the opportunity to learn what was right and what was wrong :D its much easier to see when you compare fully functional code with the one ive created :D
          – Tomas Jovanov
          Dec 14 at 22:06




          yeah i know now :D i have skipped some classes when i was in college and now im paying for them :D but luckily im at learning academy now and the teacher also explained what i have done wrong :D so thanks for the support and the quick answer, you kinda saved me there, and then i had the opportunity to learn what was right and what was wrong :D its much easier to see when you compare fully functional code with the one ive created :D
          – Tomas Jovanov
          Dec 14 at 22:06


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330849%2fjavascript-arrays-delete-duplicate-words-or-charactersif-only-characters-are-en%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

          ComboBox Display Member on multiple fields

          Is it possible to collect Nectar points via Trainline?