喉嚨比昨天更脆弱了 QQ
請多多包涵 ~"~
1
2
3Modify the spacify function so that it returns the given string with spaces insertedbetween each character.
spacify("hello world") # returns "h e l l o w o r l d"
1
2
3
4
5
6def spacify(str)
end
Test.assert_equals(spacify("hello world"),"h e l l o w o r l d");
Test.assert_equals(spacify("12345"),"1 2 3 4 5");
1
2
3
4
5
6Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number.
Example:
createPhoneNumber(Array[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) # => returns "(123) 456-7890"
The returned format must be correct in order to complete this challenge.
Don't forget the space after the closing parenthesis!
1
2
3
4
5def createPhoneNumber(numbers)
#TODO
end
Test.assert_equals(createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]), "(123) 456-7890");
影片解題:
答案:
1
2
3
4
5
6
7
8
9
10# Spacify
def spacify(str)
str.chars.join' '
end
# Create Phone Number
def createPhoneNumber(numbers)
phone = numbers.join
"(#{phone[0..2]}) #{phone[3..5]}-#{phone[6..-1]}"
end
本文同步發布於 小菜的 Blog https://riverye.com/