2 Aug 2010

小ネタ:人工推移を出すときのロジック

人工推移を出すときのロジックです。自分用のメモです。

progress_population = [115, 120, 118, 127] => [0, 115, 120, 118, 127] => [0, 115, 120, 118]

  [115, 120, 118, 127]
- [0, 115, 120, 118]
progress_population = [115, 120, 118, 127]
unshifted_progress_population = progress_population.clone.unshift(0)
unshifted_progress_population.pop

p progress_population.zip(unshifted_progress_population).map{|comparison| comparison[0].to_i - comparison[1].to_i}.flatten
=> [115, 5, -2, 9]

...もっといい書き方ないかな。