jda_m06/uf02/funcions_objectes/exercici_01.html
2022-02-16 16:13:08 +01:00

55 lines
1.4 KiB
HTML
Executable file

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<h2>Exercici 01</h2>
<p>Resultat:</p>
<p id="resultSet01"></p>
<p id="resultSet02"></p>
<script>
let usuaris = {
noms : [
"joan maria"
]
['Treball', 8],
['Menjar', 1],
['Desplaçaments', 1],
['Jugar', 1],
['Dormir', 8]
};
// SortOrder, asc(default) / desc
function sortArray(inputArray, sortOrder) {
if (sortOrder=="desc") {
return inputArray.sort().reverse();
} else {
return inputArray.sort();
}
}
// filterOption, any string you want to filter by
function filterArray(inputArray, filterOption) {
let outputArray = [];
inputArray.forEach(element => {
if (filterOption.indexOf(element[0]) != -1) {
outputArray.push(element);
}
});
return outputArray;
}
document.getElementById("resultSet01").innerHTML = sortArray(activitats, "desc");
document.getElementById("resultSet02").innerHTML = filterArray(activitats, "D");
</script>
</body>
</html>