Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9158081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:10:02+00:00 2026-06-17T13:10:02+00:00

Users will enter various serials in a textarea . Each newline will indicate a

  • 0

Users will enter various serials in a textarea. Each newline will indicate a new serial. Some requirements/restrictions:

  • Leading and trailing white spaces are not allowed.
  • White space within a serial is okay.
  • Blank serials are not allowed
  • I’d prefer to not use JQuery.
  • Store duplicates so they can be shown to the user.

Based on my tests I have a working solution. I want to make sure I’m not missing or overlooking anything. My questions are:

  • Is there a more efficient ways to check for duplicates?
  • Are there any glaring test cases that my solution won’t catch?

Working Example: http://jsbin.com/ivusuj/1/

function duplicateCheck() {
    var output = document.getElementById('Output');
    output.innerHTML = '';
    var duplicateSerials = [];
    var count = 0;
    var textArea = document.getElementById('Serials'); 
    var serials = textArea.value.trim().split(/ *\n */);

    for(var i = 0;i < serials.length;i++){
      var serial = serials[i];

      if(serials.indexOf(serial) != serials.lastIndexOf(serial) && 
         duplicateSerials.indexOf(serial) == -1 && serial !== '') {        
        duplicateSerials.push(serial);
      }  

    }    

  // For testing
  output.innerHTML = '<pre>Serials:\t' + serials.toString() + "<br />" +
                     'Duplicates:\t' + duplicateSerials.toString() + "<br>" +
                     '</pre>';
}

Note: the above is for a client side check. The same check will be performed server side as well to ensure the data is valid.


Update

Solution comparison: http://jsbin.com/ivusuj/4/edit

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:10:04+00:00Added an answer on June 17, 2026 at 1:10 pm

    I think you’d get significantly better performance if you used an object to determine which serials you’d seen before. Something closer to this:

    var seen = {};
    for (var i = 0, j = serials.length; i < j; ++i) {
      var serial = serials[i];
      if (seen.hasOwnProperty(serial)) {
        // Dupe code goes here.
        continue;
      }
      // Can't be a duplicate if we get to this point.
    }
    

    Though that won’t work with serials that use periods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tabitems. User will enter some data and save it on the
Users will be able to write some documents. Those documents will consists of chapters
in my PHP web application,I have a dataentry form where users will enter data
I have the simple need of allowing users to enter an apostrophe into various
I have a PHP Script that users will enter a name like: Alex_Newton ,
I have some forms in which users will input some numbers, I want to
I want a score to be passed to the form where users will enter
I have a textbox where user will enter the url of the image :
I have a delete form wherein the user will enter the pnum to be
I have a asp htmleditor where the user will enter any text or a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.