함수 range()

(함수 range에서 넘어옴)
range
  • Create an array containing a range of elements

1 Bash[ | ]

echo {2..9} # 2 3 4 5 6 7 8 9
echo {2..9..3} # 2 5 8
echo {9..2..3} # 9 6 3
echo {c..i} # c d e f g h i
echo {c..i..2} # c e g i
echo {A..C}{0..2} # A0 A1 A2 B0 B1 B2 C0 C1 C2
echo {002..4} # 002 003 004
seq 2 4

2 JavaScript[ | ]

<script src="//rawgit.com/kvz/phpjs/master/functions/var/print_r.js"></script>
<script src="//rawgit.com/kvz/phpjs/master/functions/array/range.js"></script>
<script>
var arr1 = range(0,4);
var arr2 = range(0,10,2);
var arr3 = range('c','g');
var arr4 = range('g','c');
document.write(print_r(arr1, true)); 
document.write(print_r(arr2, true));
document.write(print_r(arr3, true));
document.write(print_r(arr4, true)); 
// Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 )
// Array ( [0] => 0 [1] => 2 [2] => 4 [3] => 6 [4] => 8 [5] => 10 )
// Array ( [0] => c [1] => d [2] => e [3] => f [4] => g )
// Array ( [0] => g [1] => f [2] => e [3] => d [4] => c ) 
</script>

3 Perl[ | ]

use Data::Dumper;

print Dumper(0 ... 3) . "\n";
print Dumper(2 ... 3) . "\n";
print Dumper(map { 2 * $_ } 1 ... 4) . "\n";
print Dumper( reverse 0 ... 10 ) . "\n";

#$VAR1 = 0;
#$VAR2 = 1;
#$VAR3 = 2;
#$VAR4 = 3;
#
#$VAR1 = 2;
#$VAR2 = 3;
#
#$VAR1 = 2;
#$VAR2 = 4;
#$VAR3 = 6;
#$VAR4 = 8;
#
#$VAR1 = 10;
#$VAR2 = 9;
#$VAR3 = 8;
#$VAR4 = 7;
#$VAR5 = 6;
#$VAR6 = 5;
#$VAR7 = 4;
#$VAR8 = 3;
#$VAR9 = 2;
#$VAR10 = 1;
#$VAR11 = 0;

4 PHP[ | ]

$arr = range(0, 4);
print_r($arr);
$arr = range(0, 10, 2);
print_r($arr);
$arr = range('c', 'g');
print_r($arr);
$arr = range('g', 'c');
print_r($arr);

5 Python[ | ]

Python 3
print( range(4) )         # range(0, 4)
print( range(2, 4) )      # range(2, 4)
print( range(2, 10, 2) )  # range(2, 10, 2)
print( list(range(4)) )           # [0, 1, 2, 3]
print( list(range(2, 4)) )        # [2, 3]
print( list(range(2, 10, 2)) )    # [2, 4, 6, 8]
print( list(range(10, -1, -1)) )  # [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
Python 2
print( range(4) )       # [0, 1, 2, 3]
print( range(2,4) )     # [2, 3]
print( range(4,10,2) )  # [4, 6, 8]

6 R[ | ]

seq(0,4)     ## [1] 0 1 2 3 4
seq(0,10,2)  ## [1]  0  2  4  6  8 10

7 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}