Skip to content

Commit

Permalink
Entendendo funções anônimas
Browse files Browse the repository at this point in the history
  • Loading branch information
ojulio-dev committed Jan 29, 2025
1 parent e27a68b commit 9f5e69f
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@
[
"titulo" => "Meu Portfolio",
"finalizado" => false,
"data" => "2024-10-11",
"ano" => 2021,
"descricao" => "Meu primeiro Portfolio. Escrito em PHP e HTML."
],
[
"titulo" => "Lista de Tarefas",
"finalizado" => true,
"data" => "2024-05-11",
"ano" => 2022,
"descricao" => "Lista de Tarefas. Escrito em PHP e HTML."
],
[
"titulo" => "Controle de Leitura de Vídeos",
"finalizado" => true,
"data" => "2024-05-11",
"ano" => 2024,
"descricao" => "Lista de Livros. Escrito em PHP e HTML."
],
[
"titulo" => "Mais um Projeto",
"finalizado" => false,
"data" => "2025-05-11",
"ano" => 2025,
"descricao" => "Projeto secreto em andamento. Escrito em PHP e HTML."
],
// "Lista de Tarefas",
Expand All @@ -71,31 +71,31 @@ function verificarSeEstaFinalizado($p) {

}

function filtarProjetos($listaDeProjetos, $finalizado = null) {

if (is_null($finalizado)) {

return $listaDeProjetos;

}
function filtro($itens, $funcao) {

$filtrados = [];

foreach($listaDeProjetos as $projeto) {
foreach($itens as $item) {


if ($projeto['finalizado'] === $finalizado) {
if ($funcao($item)) {

$filtrados[] = $projeto;
$filtrados[] = $item;

}

}

return $filtrados;

}

};

$projetosFiltrados = filtro($projetos, function($projeto) {

return $projeto['ano'] === 2024 || $projeto['ano'] === 2021;

});

?>

<h1><?= $titulo ?></h1>
Expand All @@ -108,7 +108,7 @@ function filtarProjetos($listaDeProjetos, $finalizado = null) {

<ul>

<?php foreach(filtarProjetos($projetos, false) as $projeto): ?>
<?php foreach($projetosFiltrados as $projeto): ?>

<div

Expand All @@ -125,7 +125,7 @@ function filtarProjetos($listaDeProjetos, $finalizado = null) {

<div>

<div><?= $projeto['data'] ?></div>
<div><?= $projeto['ano'] ?></div>

<div>Projeto:

Expand Down

0 comments on commit 9f5e69f

Please sign in to comment.