분류 전체보기
-
[Ruby] Is Palindromecoding for food 2022. 7. 23. 14:26
Doh solution def is_palindrome(word) i = 0 length = word.length-1 while i true puts is_palindrome("kayak") # => true puts is_palindrome("bootcamp") # => false my code def is_palindrome(word) i = 0 palin = "" while i < word.length char = word[i] palin = char + palin i += 1 end i..
-
[Ruby] Reversecoding for food 2022. 7. 23. 13:00
Write a method reverse(word) that takes in a string word and returns the word with its letters in reverse order. my code def reverse(word) rev = "" i = word.length while i > 0 i -= 1 rev += word[i] end return rev end puts reverse("cat") # => "tac" solution def reverse(word) reversed = "" i = 0 while i < word.length char = word[i] reversed = char + reversed i += 1 end return reversed end puts rev..
-
[Ruby] Sum Numscoding for food 2022. 7. 23. 03:32
my code def sum_nums(max) i = 0 sum = 0 while i 10, because 1 + 2 + 3 + 4 = 10 puts sum_nums(5) # => 15 solution def sum_nums(max) sum = 0 i = 1 while i 10 puts sum_nums(5) # => 15 1. sum_nums(4), 구해야 하는 답이 1+2+3+4 = 10 인데 처음 시작이 1부터 max 4 이기 때문에 i = 1 로 시작하고 while에서의 조건 i 는 max 보다 작거나 같아야 한다. I wanna take i and add it to my sum, but..
-
[Ruby] Count Ecoding for food 2022. 7. 22. 11:49
Count E Write a method count_e(word) that takes in a string word and returns the number of e's in the word def count_e(word) count = 0 # use count to track the number of e's i = 0 # use i to iterate thru the word while i 1 puts count_e("excellent") # => 3
-