- 다른 뜻에 대해서는 리눅스 필터 문서를 참조하십시오.
- filter
- 함수 array_filter()
1 JavaScript[ | ]

JavaScript
Copy
var arr = ['foo', false, -1, null, ''];
console.log( arr.filter( function(a){ return a; } ) ); // ["foo", -1]
▶ | ["foo", -1] |
JavaScript
Copy
function array_filter(arr) { return arr.filter( function(a){ return a; } ) }
var arr = ['foo', false, -1, null, ''];
console.log( array_filter(arr) );
// ["foo", -1]
JavaScript
Copy
arr = [1, 4, 3, 2, 1, 2, 3, 2]
console.log( arr.filter(num => num === 2) )
// [ 2, 2, 2 ]
2 PHP[ | ]

PHP
Copy
$arr = ['foo', false, -1, null, ''];
print_r( array_filter($arr) );
# Array
# (
# [0] => foo
# [2] => -1
# )
3 Python[ | ]
Python 3
Python
Copy
numbers = [1, 2, 3, 4, 5, 6]
print( list(filter(lambda x: x%2==0, numbers)) )
# [2, 4, 6]
Python
Copy
fruits = ['Apple', 'Banana', 'Orange', 'Mango']
print( list(filter(lambda x: len(x)>5, fruits)) )
# ['Banana', 'Orange']
Python
Copy
numbers = [1, 2, 3, 4, 5, 6]
print( [x for x in numbers if x%2==0] )
# [2, 4, 6]
Python
Copy
def is_even(i):
if i%2==0: return True
return False
numbers = [1, 2, 3, 4, 5, 6]
print( list(filter(is_even, numbers)) )
# [2, 4, 6]
Python
Copy
fruits = ['Apple', 'Banana', 'Orange', 'Mango']
print( [x for x in fruits if len(x)>5] )
# ['Banana', 'Orange']
4 R[ | ]

R
Copy
v = c(11, 12, 13, 14, 15, 16)
print( v[v%%2==0] )
## [1] 12 14 16
R
Copy
v = c(1, 4, 3, 2, 1, 2, 3, 2)
print( v[v==2] )
## [1] 2 2 2
5 같이 보기[ | ]
- 함수 map() - 배열의 각 원소들에 콜백함수 적용
- 함수 reduce() - 콜백함수 사용하여 단일값으로 축소
- 함수 array_walk() - 배열의 각 원소에 대해 특정함수 적용
- lambda function
- list comprehension
- filter 함수
- WHERE 절
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.