mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-27 21:58:57 +01:00
Add anagram checker challenge
This commit is contained in:
parent
c4725e9eb2
commit
1e4d510748
2 changed files with 32 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
||||||
## Data Structures
|
## Data Structures
|
||||||
* Arrays
|
* Arrays
|
||||||
* [Add Digits](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/add_digits.rb)
|
* [Add Digits](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/add_digits.rb)
|
||||||
|
* [Anagram Checker](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/anagram_checker.rb)
|
||||||
* [Find All Duplicates In An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_all_duplicates_in_an_array.rb)
|
* [Find All Duplicates In An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_all_duplicates_in_an_array.rb)
|
||||||
* [Find The Highest Altitude](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_the_highest_altitude.rb)
|
* [Find The Highest Altitude](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_the_highest_altitude.rb)
|
||||||
* [Fizz Buzz](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/fizz_buzz.rb)
|
* [Fizz Buzz](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/fizz_buzz.rb)
|
||||||
|
|
31
data_structures/arrays/anagram_checker.rb
Normal file
31
data_structures/arrays/anagram_checker.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# Challenge name: Is anagram
|
||||||
|
#
|
||||||
|
# Given two strings s and t , write a function to determine
|
||||||
|
# if t is an anagram of s.
|
||||||
|
#
|
||||||
|
# Note:
|
||||||
|
# You may assume the string contains only lowercase alphabets.
|
||||||
|
#
|
||||||
|
# Follow up:
|
||||||
|
# What if the inputs contain unicode characters?
|
||||||
|
# How would you adapt your solution to such case?
|
||||||
|
#
|
||||||
|
# @param {String} s
|
||||||
|
# @param {String} t
|
||||||
|
# @return {Boolean}
|
||||||
|
|
||||||
|
def is_anagram(s, t)
|
||||||
|
end
|
||||||
|
|
||||||
|
s = 'anagram'
|
||||||
|
t = 'nagaram'
|
||||||
|
puts(is_anagram(s, t))
|
||||||
|
# => true
|
||||||
|
s = 'rat'
|
||||||
|
t = 'car'
|
||||||
|
puts(is_anagram(s, t))
|
||||||
|
# => false
|
||||||
|
s = 'a'
|
||||||
|
t = 'ab'
|
||||||
|
puts(is_anagram(s, t))
|
||||||
|
# => false
|
Loading…
Reference in a new issue