xxxxxxxxxx
# filter function
l1=[10,20,30,40,50,60,70,80]
l2= [i for i in filter(lambda x:x>30,l1)]
print(l2)
# [40, 50, 60, 70, 80]
# filter takes a function and a collection. It returns a collection of every item for which the function returned True.
xxxxxxxxxx
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const filter = arr.filter((number) => number > 5);
console.log(filter); // [6, 7, 8, 9]
xxxxxxxxxx
const products = [
{ name: 'Laptop', price: 32000, brand: 'Lenovo', color: 'Silver' },
{ name: 'Phone', price: 700, brand: 'Iphone', color: 'Golden' },
{ name: 'Watch', price: 3000, brand: 'Casio', color: 'Yellow' },
{ name: 'Aunglass', price: 300, brand: 'Ribon', color: 'Blue' },
{ name: 'Camera', price: 9000, brand: 'Lenovo', color: 'Gray' },
];
//Get products that price is greater than 3000 by using a filter
const getProduct = products.filter(product => product.price > 3000);
console.log(getProduct)
//Expected output:
/*[
{ name: 'Laptop', price: 32000, brand: 'Lenovo', color: 'Silver' },
{ name: 'Camera', price: 9000, brand: 'Lenovo', color: 'Gray' }
]
*/
xxxxxxxxxx
const forwardFn = (id) => {
console.log(id);
const filteredArray = state.filter((e, index) => {
console.log(index);
return index !== id;
});
setstate(filteredArray);
}; aka
xxxxxxxxxx
const grades = [10, 2, 21, 35, 50, -10, 0, 1];
// get all grades > 20
const result = grades.filter(grade => grade > 20); // [21, 35, 50];
// get all grades > 30
grades.filter(grade => grade > 30); // [35, 50]
xxxxxxxxxx
let arr = [1, 2, 3, 4, 5]; // filter function in JS
let newArr = arr.filter((item) => {
return item % 2 == 0;
})
console.log(newArr)
// -- filters the array and return those items which are even
xxxxxxxxxx
select *
from toys
where toy_name ='Sir Stripypants' OR colour ='blue'
AND price = 6;
xxxxxxxxxx
var jsonarr = [
{
id: 1,
name: "joe"
},
{
id: -19,
name: "john"
},
{
id: 20,
name: "james"
},
{
id: 25,
name: "jack"
},
{
id: -10,
name: "joseph"
},
{
id: "not a number",
name: "jimmy"
},
{
id: null,
name: "jeff"
},
]
var result = jsonarr.filter(user => user.id > 0);
console.log(result);
xxxxxxxxxx
class FilterOperation {
public static void main(String[] args) {
Stream.of(34,678,89,4,52,31,325,6)
.filter(e -> e%2 == 0)
.forEach(e -> System.out.println(e));
}
}