原文:(Doing this in languages like C or Java would take you a lot of boiler plate code. The beauty of Ruby is in its concise but readable code.)
4给定一个包含有几个字符串的数组,编写一个length_finder方法,该方法接收一个数组为参数并够返回一个新数组,该新数组为对应数组参数的每个字符串元素的长度。(别吐槽我的水平了,我知道这个翻译的那是怎么听怎么别扭,应该能明白大概意思吧)Example:
Given ['Ruby','Rails','C42'] the method should return [4,5,3]
def length_finder(input_array)
input_array.map do |e|
e.length
end
end
复制代码
4给定一个包含有多个单词的句子,编写一个名为“find_frequency”的方法,该方法有两个参数“sentence”和“word”,这两个参数都是字符串对象。并返回某一单词在该句子中的出现频率。示例:传入 'Ruby is The best language in the World' 和 'the',则返回“ 2”
提示: Array#count (用法自个儿查去)
五、构建一个计算器
创建一个计算器类,能够在同一时间完成两个数字的加减法。(不太懂,原文:Create a class Calculator, which performs the addition and subtraction of two numbers at a time. The sample code explains the expected API.)