Project

uniq_char

0.0
No commit activity in last 3 years
No release in over 3 years
Find first uniq character in a string
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Project Readme

UniqChar

Gem Version Codeship Status for zhitongLIU/uniq_char Patreon

Table of Contents

  • Features
  • Requirements
  • Setup
  • Usage
  • Tests
  • Versioning
  • Code of Conduct
  • Contributions
  • License
  • History
  • Credits

Features

Requirements

  1. MRI 2.2.3

Setup

For an insecure install, type the following (not recommended):

gem install uniq_char

Add the following to your Gemfile:

gem "uniq_char"

Usage

  require 'uniq_char'

  'aabbce'.first_uniq_char
  # => 'c'

  'aabbce'.first_uniq_char2
  # => 'c'

  'aabbce'.uniq_chars
  # => ['c', 'e']

  'aabbce'.uniq_chars.first
  # => 'c'

Tests

To test, run:

bundle exec rake

Benchmark

$ ruby spec/benchmark.rb
 "Benchmark with 50 chars"
        user     system      total        real
 first_uniq_char  0.000000   0.000000   0.000000 (  0.000014)
 first_uniq_char2  0.000000   0.000000   0.000000 (  0.000028)
 uniq_chars.first  0.000000   0.000000   0.000000 (  0.000052)
 "Benchmark with 500 chars"
        user     system      total        real
 first_uniq_char  0.000000   0.000000   0.000000 (  0.000180)
 first_uniq_char2  0.000000   0.000000   0.000000 (  0.000234)
 uniq_chars.first  0.000000   0.000000   0.000000 (  0.000232)
 "Benchmark with 5000 chars"
        user     system      total        real
 first_uniq_char  0.000000   0.000000   0.000000 (  0.003596)
 first_uniq_char2  0.000000   0.000000   0.000000 (  0.001695)
 uniq_chars.first  0.000000   0.000000   0.000000 (  0.001970)

Conclusion:

Second & third implementation is better when having more characters

Versioning

0.2.0

Code of Conduct

Please note that this project is released with a CODE OF CONDUCT. By participating in this project you agree to abide by its terms.

Contributions

Read CONTRIBUTING for details.

License

Copyright (c) 2017 . Read the LICENSE for details.

History

Read the CHANGELOG for details. Built with Gemsmith.

Credits

Developed by zhitongLIU at .