你必須很努力

壓線前逼自己刷一題 Codewars

2019/09/17
字數統計: 225閱讀時間: 1 min

今天整個忙翻,回到家打開電腦已經 22:30 左右
逼自己要在 12:00 前 po
給你自己承諾要堅持下去
怕來不及 po 文,因此今天題目比較簡單些
挑戰的是Codewars LV7 的題目


題目

1
2
3
4
5
An 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
10
def 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
12
def 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/

原文連結:https://riverye.com/2019/09/17/壓線前逼自己刷一題-Codewars/

發表日期:2019-09-17

更新日期:2022-12-21

CATALOG