uniq_char 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -5
- data/lib/uniq_char.rb +15 -2
- data/lib/uniq_char/identity.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 977a90e7afd4bde5c724c4ff781420b3f584e52d
|
4
|
+
data.tar.gz: e2ee7aa5c2ad58c2bc4a1da44d9500bc99d1c7fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5080ac9204bb05230777acde551bd0bb74015333e6a7dc332ab218479dbcbfdf453896199f39dd81ca8ec36ab6c9862e674f188e5291b13c680106db322f938
|
7
|
+
data.tar.gz: 83b1be9bac5bc5322e9f19590a6305ec6b3a938cd63352d91d909707eafe70be3da3db1c6d6dcfddf269f78408a423adfd3f1753af383635bb1d318ad2931517
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# UniqChar
|
2
2
|
|
3
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
|
5
|
-
[![Code Climate Coverage](https://codeclimate.com/github
|
6
|
-
[![Gemnasium Status](https://gemnasium.com
|
7
|
-
[![Travis CI Status](https://secure.travis-ci.org
|
4
|
+
[![Code Climate GPA](https://codeclimate.com/github/zhitongliu/uniq_char.svg)](https://codeclimate.com/github/zhitongliu/uniq_char)
|
5
|
+
[![Code Climate Coverage](https://codeclimate.com/github/zhitongliu/uniq_char/coverage.svg)](https://codeclimate.com/github/zhitongliu/uniq_char)
|
6
|
+
[![Gemnasium Status](https://gemnasium.com/zhitongliu/uniq_char.svg)](https://gemnasium.com/zhitongliu/uniq_char)
|
7
|
+
[![Travis CI Status](https://secure.travis-ci.org/zhitongliu/uniq_char.svg)](https://travis-ci.org/zhitongliu/uniq_char)
|
8
8
|
[![Patreon](https://img.shields.io/badge/patreon-donate-brightgreen.svg)](https://www.patreon.com/)
|
9
9
|
|
10
10
|
<!-- Tocer[start]: Auto-generated, don't remove. -->
|
@@ -47,8 +47,15 @@ Add the following to your Gemfile:
|
|
47
47
|
|
48
48
|
'aabbce'.first_uniq_char
|
49
49
|
# => 'c'
|
50
|
+
|
50
51
|
'aabbce'.first_uniq_char2
|
51
52
|
# => 'c'
|
53
|
+
|
54
|
+
'aabbce'.uniq_chars
|
55
|
+
# => ['c', 'e']
|
56
|
+
|
57
|
+
'aabbce'.uniq_chars.first
|
58
|
+
# => 'c'
|
52
59
|
```
|
53
60
|
# Tests
|
54
61
|
|
data/lib/uniq_char.rb
CHANGED
@@ -23,12 +23,25 @@ class String
|
|
23
23
|
# >> 'aabbce'.first_uniq_char2
|
24
24
|
# => c
|
25
25
|
#
|
26
|
-
#
|
27
|
-
#
|
26
|
+
# could be refactor by doing just returning uniq_chars.first
|
27
|
+
# but the best case will become 2n
|
28
28
|
nb_count = {}
|
29
29
|
chars.each { |c| nb_count[c] = nb_count[c].nil? ? 1 : nb_count[c] + 1 }
|
30
30
|
couple = nb_count.find { |_k, v| v == 1 }
|
31
31
|
# return the key of the key value couple(the first one in the couple)
|
32
32
|
couple.nil? ? nil : couple.first
|
33
33
|
end
|
34
|
+
|
35
|
+
def uniq_chars
|
36
|
+
# returns list of uniq chars in a string
|
37
|
+
# Example:
|
38
|
+
# >> 'aabbce'.uniq_chars
|
39
|
+
# => [c, e]
|
40
|
+
#
|
41
|
+
nb_count = {}
|
42
|
+
uniqs = []
|
43
|
+
chars.each { |c| nb_count[c] = nb_count[c].nil? ? 1 : nb_count[c] + 1 }
|
44
|
+
nb_count.each { |k, v| uniqs << k if v == 1 }
|
45
|
+
uniqs.uniq
|
46
|
+
end
|
34
47
|
end
|
data/lib/uniq_char/identity.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uniq_char
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhitongLIU
|
@@ -235,7 +235,7 @@ files:
|
|
235
235
|
- lib/tasks/rubocop.rake
|
236
236
|
- lib/uniq_char.rb
|
237
237
|
- lib/uniq_char/identity.rb
|
238
|
-
homepage: https://github.com
|
238
|
+
homepage: https://github.com/zhitongliu/uniq_char
|
239
239
|
licenses:
|
240
240
|
- MIT
|
241
241
|
metadata: {}
|