Giter Site home page Giter Site logo

encdec's Introduction

encdec's People

Contributors

ianoxley avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

encdec's Issues

Incorrect caching of digits within alphabet

Code that exhibits the bug:

var base24 = encdec('BCDFGHJKLMNPQRSTVWXZ1345');

base24.encode( 1 )
// Correctly encodes 1 to 'C'
// caches as {1 : 'C'}

base24.decode( '1' );
// Should decode to 20, but it returns 'C' due to cache

/* If done in reverse, {1 : 20} would have been cached and
   base24.encode( 1 ) would have incorrectly returned 20
*/

If 0-9 do not map to themselves, they will be incorrectly cached.

Can't encode zeroes

Basically, I'm trying to work with zeroes, but it returns an empty string instead of the correct letter.

var base24 = encdec('BCDFGHJKLMNPQRSTVWXZ1345');
console.log( base24.encode(0) ); // Should return 'B', but returns ''

I had a look, and I think this occurs because encdec checks num as a boolean here, treating 0 as false:

if (num) {
  encode = alphabet[num] + encode;
}

Possible fix:

if (num>=0) {
  encode = alphabet[num] + encode;
}

It's possible that this check isn't even necessary.

License?

Hey Ian,

I noticed there wasn't a license associated with this project. Would you be willing to release it under a BSD style license so I can use it in one of my projects?

Jud

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.