uniq_char 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d8f2dbbb414a74170629b4fb677fbffab3f1ef3
4
- data.tar.gz: cc8522fc3c3f44dea79738b2ae29335cf2c532b2
3
+ metadata.gz: 977a90e7afd4bde5c724c4ff781420b3f584e52d
4
+ data.tar.gz: e2ee7aa5c2ad58c2bc4a1da44d9500bc99d1c7fa
5
5
  SHA512:
6
- metadata.gz: 1d578f4542ea4f54bd7cb334690541e1f7412326a0b4612302ac30208c01a83941f8d51e4a759f6c0edfb7e5de3539c8b0e9b75a4702ca0133462292d11cdefb
7
- data.tar.gz: d25011f6b9d2f56023d35ccb799a5519aaa9e3ec18eeea58c8f78240f6439f6f3f67852893092926d1b98d1f6aad613f4ac81a7ffa17aa5c02fa3e6cb761ef6d
6
+ metadata.gz: d5080ac9204bb05230777acde551bd0bb74015333e6a7dc332ab218479dbcbfdf453896199f39dd81ca8ec36ab6c9862e674f188e5291b13c680106db322f938
7
+ data.tar.gz: 83b1be9bac5bc5322e9f19590a6305ec6b3a938cd63352d91d909707eafe70be3da3db1c6d6dcfddf269f78408a423adfd3f1753af383635bb1d318ad2931517
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # FirstDiffChar
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//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)
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
- # Arguments:
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
@@ -10,7 +10,7 @@ module UniqChar
10
10
  end
11
11
 
12
12
  def self.version
13
- '0.1.0'
13
+ '0.2.0'
14
14
  end
15
15
 
16
16
  def self.version_label
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.1.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//uniq_char
238
+ homepage: https://github.com/zhitongliu/uniq_char
239
239
  licenses:
240
240
  - MIT
241
241
  metadata: {}