uniq_char 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0d8f2dbbb414a74170629b4fb677fbffab3f1ef3
4
+ data.tar.gz: cc8522fc3c3f44dea79738b2ae29335cf2c532b2
5
+ SHA512:
6
+ metadata.gz: 1d578f4542ea4f54bd7cb334690541e1f7412326a0b4612302ac30208c01a83941f8d51e4a759f6c0edfb7e5de3539c8b0e9b75a4702ca0133462292d11cdefb
7
+ data.tar.gz: d25011f6b9d2f56023d35ccb799a5519aaa9e3ec18eeea58c8f78240f6439f6f3f67852893092926d1b98d1f6aad613f4ac81a7ffa17aa5c02fa3e6cb761ef6d
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2017 []().
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # FirstDiffChar
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/uniq_char.svg)](http://badge.fury.io/rb/uniq_char)
4
+ [![Code Climate GPA](https://codeclimate.com/github//uniq_char.svg)](https://codeclimate.com/github//uniq_char)
5
+ [![Code Climate Coverage](https://codeclimate.com/github//uniq_char/coverage.svg)](https://codeclimate.com/github//uniq_char)
6
+ [![Gemnasium Status](https://gemnasium.com//uniq_char.svg)](https://gemnasium.com//uniq_char)
7
+ [![Travis CI Status](https://secure.travis-ci.org//uniq_char.svg)](https://travis-ci.org//uniq_char)
8
+ [![Patreon](https://img.shields.io/badge/patreon-donate-brightgreen.svg)](https://www.patreon.com/)
9
+
10
+ <!-- Tocer[start]: Auto-generated, don't remove. -->
11
+
12
+ # Table of Contents
13
+
14
+ - [Features](#features)
15
+ - [Requirements](#requirements)
16
+ - [Setup](#setup)
17
+ - [Usage](#usage)
18
+ - [Tests](#tests)
19
+ - [Versioning](#versioning)
20
+ - [Code of Conduct](#code-of-conduct)
21
+ - [Contributions](#contributions)
22
+ - [License](#license)
23
+ - [History](#history)
24
+ - [Credits](#credits)
25
+
26
+ <!-- Tocer[finish]: Auto-generated, don't remove. -->
27
+
28
+ # Features
29
+
30
+ # Requirements
31
+
32
+ 0. [MRI 2.2.3](https://www.ruby-lang.org)
33
+
34
+ # Setup
35
+
36
+ For an insecure install, type the following (not recommended):
37
+
38
+ gem install uniq_char
39
+
40
+ Add the following to your Gemfile:
41
+
42
+ gem "uniq_char"
43
+
44
+ # Usage
45
+ ```ruby
46
+ require 'uniq_char'
47
+
48
+ 'aabbce'.first_uniq_char
49
+ # => 'c'
50
+ 'aabbce'.first_uniq_char2
51
+ # => 'c'
52
+ ```
53
+ # Tests
54
+
55
+ To test, run:
56
+
57
+ bundle exec rake
58
+
59
+ # Versioning
60
+ 0.1.0
61
+
62
+ # Code of Conduct
63
+
64
+ Please note that this project is released with a [CODE OF CONDUCT](CODE_OF_CONDUCT.md). By participating in this project
65
+ you agree to abide by its terms.
66
+
67
+ # Contributions
68
+
69
+ Read [CONTRIBUTING](CONTRIBUTING.md) for details.
70
+
71
+ # License
72
+
73
+ Copyright (c) 2017 []().
74
+ Read the [LICENSE](LICENSE.md) for details.
75
+
76
+ # History
77
+
78
+ Read the [CHANGELOG](CHANGELOG.md) for details.
79
+ Built with [Gemsmith](https://github.com/bkuhlmann/gemsmith).
80
+
81
+ # Credits
82
+
83
+ Developed by [zhitongLIU]() at []().
@@ -0,0 +1,6 @@
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ rescue LoadError => error
5
+ puts error.message
6
+ end
@@ -0,0 +1,6 @@
1
+ begin
2
+ require 'rubocop/rake_task'
3
+ RuboCop::RakeTask.new
4
+ rescue LoadError => error
5
+ puts error.message
6
+ end
@@ -0,0 +1,20 @@
1
+ module UniqChar
2
+ # Gem identity information.
3
+ module Identity
4
+ def self.name
5
+ 'uniq_char'
6
+ end
7
+
8
+ def self.label
9
+ 'UniqChar'
10
+ end
11
+
12
+ def self.version
13
+ '0.1.0'
14
+ end
15
+
16
+ def self.version_label
17
+ "#{label} #{version}"
18
+ end
19
+ end
20
+ end
data/lib/uniq_char.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'uniq_char/identity'
2
+
3
+ #
4
+ class String
5
+ def first_uniq_char
6
+ # easiest implementation to get the first char which has only one count
7
+ # O(n^2) worst case, best 1
8
+ #
9
+ # Example:
10
+ # >> 'aabbce'.first_uniq_char
11
+ # => c
12
+ #
13
+ # Arguments:
14
+ #
15
+ each_char.find { |c| count(c) == 1 }
16
+ end
17
+
18
+ def first_uniq_char2
19
+ # liner implementation
20
+ # O(2n) worst case, best n + 1
21
+ #
22
+ # Example:
23
+ # >> 'aabbce'.first_uniq_char2
24
+ # => c
25
+ #
26
+ # Arguments:
27
+ #
28
+ nb_count = {}
29
+ chars.each { |c| nb_count[c] = nb_count[c].nil? ? 1 : nb_count[c] + 1 }
30
+ couple = nb_count.find { |_k, v| v == 1 }
31
+ # return the key of the key value couple(the first one in the couple)
32
+ couple.nil? ? nil : couple.first
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,262 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uniq_char
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - zhitongLIU
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gemsmith
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-remote
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-state
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-rescue
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-stack_explorer
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rb-fsevent
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: terminal-notifier
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: terminal-notifier-guard
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rubocop
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: codeclimate-test-reporter
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ description: Find first uniq character in a string
224
+ email:
225
+ - zhitonggm.liu@gmail.com
226
+ executables: []
227
+ extensions: []
228
+ extra_rdoc_files:
229
+ - README.md
230
+ - LICENSE.md
231
+ files:
232
+ - LICENSE.md
233
+ - README.md
234
+ - lib/tasks/rspec.rake
235
+ - lib/tasks/rubocop.rake
236
+ - lib/uniq_char.rb
237
+ - lib/uniq_char/identity.rb
238
+ homepage: https://github.com//uniq_char
239
+ licenses:
240
+ - MIT
241
+ metadata: {}
242
+ post_install_message:
243
+ rdoc_options: []
244
+ require_paths:
245
+ - lib
246
+ required_ruby_version: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ required_rubygems_version: !ruby/object:Gem::Requirement
252
+ requirements:
253
+ - - ">="
254
+ - !ruby/object:Gem::Version
255
+ version: '0'
256
+ requirements: []
257
+ rubyforge_project:
258
+ rubygems_version: 2.4.5.1
259
+ signing_key:
260
+ specification_version: 4
261
+ summary: Find first uniq character in a string
262
+ test_files: []