Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why will a Range not work when descending? [duplicate]

Tags:

range

ruby

Why will (1..5).each iterate over 1,2,3,4,5, but (5..1) will not? It returns the Range instead.

1.9.2p290 :007 > (1..5).each do |i| puts i end 1 2 3 4 5  => 1..5 1.9.2p290 :008 > (5..1).each do |i| puts i end  => 5..1 
like image 698
larryzhao Avatar asked Jan 11 '12 16:01

larryzhao


People also ask

Why won't duplicate values work in Excel?

Trailing or leading spaces Probably the most common cause of Excel not recognizing duplicates. Check if the one cell has trailing, leading or extra spaces in the cell. Excel sees the space as an individual character but humans tend to ignore it.

Why does merging cells only keeps the upper left value?

Warning before you start merging cells! If the cells contain data or formulas, then you will lose anything not in the upper left cell. A warning dialog box will appear telling you Merging cells only keeps the upper-left value and discards other values.

How do you rank in Excel if there are duplicates?

If another duplicate is encountered, the rank value is increased by 2, and so on. You can use the RANK function to rank numeric values. RANK has two modes of operation: ranking values so that the largest value is ranked #1 (order = 0), and ranking values so that the smallest value is #1 (order = 1).


1 Answers

The easiest way to do that is use downto

5.downto(1) do |i| puts i end 
like image 131
Derek Organ Avatar answered Sep 26 '22 12:09

Derek Organ