Skip to content

Commit

Permalink
➕ feat: problem4
Browse files Browse the repository at this point in the history
  • Loading branch information
linder3hs committed Mar 9, 2024
1 parent 87c99de commit ee73021
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion semana-6/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script defer src="./problems3.js"></script>
<!-- <script defer src="./problems3.js"></script> -->
<script defer src="./problem4.js"></script>
</head>
<body></body>
</html>
33 changes: 33 additions & 0 deletions semana-6/problem4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function manufacture(gifts, materials) {
const results = [];
gifts.forEach(function (gift) {
let condition = true;
for (let word of gift.split("")) {
if (materials.indexOf(word) === -1) {
condition = false;
break;
}
}

if (condition) results.push(gift);
});

return results;
}

const gifts = ["tren", "oso", "pelota"];
const materials = "tronesa";
console.log(manufacture(gifts, materials)); // ["tren", "oso"]
// 'tren' SÍ porque sus letras están en 'tronesa'
// 'oso' SÍ porque sus letras están en 'tronesa'
// 'pelota' NO porque sus letras NO están en 'tronesa'

const gifts2 = ["juego", "puzzle"];
const materials2 = "jlepuz";

console.log(manufacture(gifts2, materials2)); // ["puzzle"]

const gifts3 = ["libro", "ps5"];
const materials3 = "psli";

console.log(manufacture(gifts3, materials3)); // []

0 comments on commit ee73021

Please sign in to comment.