Esempio n. 1
0
 public function testFilter()
 {
     // Arrange
     $a = [1, 2, 3, 4, 5];
     $b = [['name' => 'fred', 'age' => 32], ['name' => 'maciej', 'age' => 16]];
     // Act
     $x = __::filter($a, function ($n) {
         return $n > 3;
     });
     $y = __::filter($b, function ($n) {
         return $n['age'] == 16;
     });
     // Assert
     $this->assertEquals([4, 5], $x);
     $this->assertEquals([$b[1]], $y);
 }
 function filter_unselected()
 {
     $this->contents = __::filter($this->contents, function ($block) {
         return $block->selected === true;
     });
 }
Esempio n. 3
0
 public function testFilter()
 {
     $object = array(1, 2, 3, 4, 5);
     $return = array(2, 4);
     $result = __::filter($object, function ($num) {
         if ($num % 2 == 0) {
             return true;
         } else {
             return false;
         }
     });
     $this->assertEquals($return, $result);
 }
 public function testFilter()
 {
     // from js
     $evens = __::filter(array(1, 2, 3, 4, 5, 6), function ($num) {
         return $num % 2 === 0;
     });
     $this->assertEquals(array(2, 4, 6), $evens, 'selected each even number');
     // extra
     $odds = __(array(1, 2, 3, 4, 5, 6))->filter(function ($num) {
         return $num % 2 !== 0;
     });
     $this->assertEquals(array(1, 3, 5), $odds, 'works with OO-style calls');
     $evens = __::filter(array(1, 2, 3, 4, 5, 6), function ($num) {
         return $num % 2 === 0;
     });
     $this->assertEquals(array(2, 4, 6), $evens, 'aliased as filter');
     $iterator = function ($num) {
         return $num % 2 !== 0;
     };
     $this->assertEquals(__::filter(array(1, 3, 5), $iterator), __::select(array(1, 3, 5), $iterator), 'alias works');
     // docs
     $this->assertEquals(array(2, 4), __::filter(array(1, 2, 3, 4), function ($num) {
         return $num % 2 === 0;
     }));
 }