Skip to content

1.6 Length bug #14

Open
Open

Description

@dawsbot

The way that string length is compared and calculated is not correct when strings have significant entropy. See my branch showing this here @tankwan

Activity

  1. changed the title [-]1.6 length bug[/-] [+]1.6 Length bug[/+] on May 21, 2017
  2. dawsbot commented on May 21, 2017

    @dawsbot
    ContributorAuthor

    Do you want to fix this @tankwan? I can if not.

  3. heytonytan commented on May 22, 2017

    @heytonytan
    Collaborator
  4. profnandaa commented on Oct 2, 2018

    @profnandaa
    Collaborator

    @thetonytan - ping!

  5. yuriaps commented on Sep 27, 2020

    @yuriaps

    Bug in this test
    console.log('aabbcc', strComp('aabbcc'), 'aabbcc')
    As the book says, if the length of the result is not less than the original should print the original, and it is printing:
    a2b2c2

  6. yuriaps commented on Sep 27, 2020

    @yuriaps

    I don't see why use the Math.max()...
    I would go this way

    var strComp = function(string) {
        var compressed = '';
        var currChar = '';
        var currCount = '';
        for (var i = 0; i < string.length; i++) {
          if (currChar !== string[i]) {
            compressed = compressed + currChar + currCount;
            currChar = string[i];
            currCount = 1;
          } else {
            currCount++;
          }
        }
        compressed = compressed + currChar + currCount;
      
        return compressed.length >= string.length ? string : compressed;
      };
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions