小编Gav*_*vin的帖子

Ruby Hash:根据值(值为数组)排序哈希值

我希望根据哈希值的重新排序返回一个新的哈希值.值本身就是整数数组.

例如:

hsh = {"c2" => [44,2], "c1" => [11,33], "c9" => [23,7]}
Run Code Online (Sandbox Code Playgroud)

我希望能够根据值中的值0或值1返回重新排序的哈希值.

这里的任何帮助都非常感谢 - 谢谢大家.

ruby arrays hash

3
推荐指数
1
解决办法
257
查看次数

Ruby 1.9.2 - 多个splat参数问题

Ruby的新手,我正在尝试接受方法中的多个splat参数.我想我理解为什么它给我编译错误,但我不知道如何解决它.任何有关如何在参数中使用多个splats的帮助都会有所帮助.提前感谢您的任何指导.

def find_max_expenses(salary, save_prcnt, *pre_ret_g_rates, *post_ret_g_rates, epsilon)
 years = pre_ret_g_rates.count
 savings = nest_egg_variable(salary, save_prcnt, pre_ret_g_rates)
 savings = savings[-1]
 low = 0
 high = savings
 expenses = (low + high) / 2

 # can use the [-1] at the end is equivalent to the code below
 remaining_money = post_retirement(savings, post_ret_g_rates, expenses)   #[-1]
 remaining_money = remaining_money[-1]
 while remaining_money > epsilon       # the value we want to stay above
  if remaining_money > 0
   low = expenses
  else
   high = expenses
  end
  expenses = …
Run Code Online (Sandbox Code Playgroud)

ruby methods arguments splat

0
推荐指数
1
解决办法
1214
查看次数

标签 统计

ruby ×2

arguments ×1

arrays ×1

hash ×1

methods ×1

splat ×1