This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$data = array_map(function ($elem) { | |
return ['elem' => $elem, 'nested' => []]; | |
}, [1, 2, 2, 3, 4, 1, 2, 1, 1, 2, 2]); | |
function group($data) { | |
$subs = false; | |
$data = array_chunk($data, 2); | |
$results = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function transpose($matrix) { | |
return array_map(function ($column) use ($matrix) { | |
return array_column($matrix, $column); | |
}, array_keys($matrix[0])); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function transpose($matrix) { | |
return array_reduce(array_keys($matrix[0]), function ($transposed, $column) use ($matrix) { | |
$transposed[] = array_column($matrix, $column); | |
return $transposed; | |
}, []); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function transpose($matrix) { | |
for ($column = 0; $column < count($matrix[0]); $column++) { | |
for ($row = 0; $row < count($matrix); $row++) { | |
$transposed[$column][] = $matrix[$row][$column]; | |
} | |
} | |
return $transposed; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function transpose($matrix) { | |
$transposed = []; | |
for ($column = 0; $column < count($matrix[0]); $column++) { | |
$transposed[$column] = []; | |
for ($row = 0; $row < count($matrix); $row++) { | |
$transposed[$column][] = $matrix[$row][$column]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function transpose($matrix) { | |
$transposed = []; | |
$numberOfColumns = count($matrix[0]); | |
$numberOfRows = count($matrix); | |
for ($column = 0; $column < $numberOfColumns; $column++) { | |
$transposed[$column] = []; | |
for ($row = 0; $row < $numberOfRows; $row++) { | |
$transposed[$column][] = $matrix[$row][$column]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function transpose($matrix) { | |
$transposed = []; | |
$numberOfColumns = count($matrix[0]); | |
$numberOfRows = count($matrix); | |
for ($column = 0; $column < $numberOfColumns; $column++) { | |
for ($row = 0; $row < $numberOfRows; $row++) { | |
if (! isset($transposed[$column])) { | |
$transposed[$column] = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$this->reduce(function ($transposed, $_) { | |
return $transposed->push($this->pluck($transposed->count())); | |
}, new static)->filter(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function transpose ($matrix) { | |
return array_reduce(array_keys($matrix[0]), function ($transposed, $column) use ($matrix) { | |
$transposed[] = array_column($matrix, $column); | |
return $transposed; | |
}, []); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Numberset | |
{ | |
// class definition | |
public function odd() | |
{ | |
$mutant = new static($this->min, $this->max); | |
$mutant->numbers = array_filter($this->numbers, function ($number) { |