Coder Social home page Coder Social logo

nth's Introduction

nth

Indexing arrays is a touchy subject. Some morons think it should be done based on offset like in that outdated language from nearly 50 years ago (C). The rest of us understand that it should really be based on ordinal numbers. This library adds the capability to use ordinal numbers for extra readability. Don't worry, 0-indexers, you can keep believing the earth is flat, this library won't force you to use ordinal numbers.

Check out the following examples of the increase in readability!

my_array = [:first, :second, :third]
my_array[1]

The above example read aloud says "the second element of my_array", but it's using the numeral 1, but it's written right to left.

my_array = [:first, :second, :third]
my_array[2.nd]

The above example read aloud says "the second element of my_array", and it's using the numeral 2, but it's written right to left. This way is clearly better.

my_array = [:first, :second, :third]
2.nd.element_of my_array

The above example read aloud says "the second element of my_array", and it's written left to right. This way is obviously the most superior.

Installation

Add this to your application's shard.yml:

dependencies:
  nth:
    github: willamin/nth

Usage

require "nth"

Integers get a few new methods added: .st, .nd, .rd, .th. Exceptions are raised when the methods are used on the wrong numbers, because I'm a bit of stickler Meeseeks. Integers also get the methods .element_of(Array), and in(Array) which returns โ€” drumroll please โ€” the element of the array corresponding with the integer. Big surprise there.

Development

Make a failing test that shows the feature you'd like the library to have. Fix the test.

Contributing

  1. Fork it ( https://github.com/willamin/nth/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

nth's People

Contributors

willamin avatar wa9ace avatar

Stargazers

Bobby Burden III avatar

Watchers

James Cloos avatar

nth's Issues

Better Modularization

As fun as it is to just reopen structs all over the place, we should really move the method definitions to our own Nth module, and include the module in the integer structs.

Better Struct Selection

While this package is amazing, it only works with Int32 structs. We should make this work perfectly with all other number structs.

Better tests

When developing this library, I just hacked together a single test that dealt with the features I wanted. This test really needs to be separated into separate tests, each detailing a separate feature.

Better Documentation

All the hip, new, and exciting packages always have fun websites and logos. Nth could use some of that love.

Oh and maybe some more documentation, I don't know.

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.