今天整個忙翻,回到家打開電腦已經 22:30 左右
逼自己要在 12:00 前 po廢文
給你自己承諾要堅持下去
怕來不及 po 文,因此今天題目比較簡單些
挑戰的是Codewars LV7 的題目
題目:
1
2
3
4
5An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case.
is_isogram("Dermatoglyphics" ) == true
is_isogram("aba" ) == false
is_isogram("moOse" ) == false # -- ignore letter case
1
2
3
4
5
6
7
8
9
10def is_isogram(string)
#your code here
end
Test.assert_equals(is_isogram("Dermatoglyphics"), true )
Test.assert_equals(is_isogram("isogram"), true )
Test.assert_equals(is_isogram("aba"), false, "same chars may not be adjacent" )
Test.assert_equals(is_isogram("moOse"), false, "same chars may not be same case" )
Test.assert_equals(is_isogram("isIsogram"), false )
Test.assert_equals(is_isogram(""), true, "an empty string is a valid isogram" )
影片解題:
答案:
1
2
3
4
5
6
7
8
9
10
11
12def isIsogram(string)
# if string.downcase.chars.uniq == string.downcase.chars
# true
# else
# false
# end
# return true if string.downcase.chars.uniq == string.downcase.chars
# false
string.downcase.chars.uniq == string.downcase.chars
end
本文同步發布於 小菜的 Blog https://riverye.com/