Skip to content

Instantly share code, notes, and snippets.

@aguileraq
Created June 26, 2018 20:49
Show Gist options
  • Save aguileraq/b0f103ae4df9b7b0d8d46ce2535c5137 to your computer and use it in GitHub Desktop.
Save aguileraq/b0f103ae4df9b7b0d8d46ce2535c5137 to your computer and use it in GitHub Desktop.
//Ejercicio 1
var arr = ["Acoxpa - Auditorio", "Polanco - Santa Fe", "Acoxpa - Auditorio", "Reforma - Coacalco", "Acoxpa - Auditorio", "Polanco - Santa Fe"];
function count(arr){
arr.sort();
var result = [];
var current;
var count = 0;
for (var i = 0; i <= arr.length; i++){
if (arr[i] != current) {
if (count > 0) {
result.push({"ruta":current,"veces":count});
}
current = arr[i];
count = 1;
} else {
count++;
}
}
return result;
}
console.log(count(arr));
//Ejercicio2
var ejer2 = [{
name: "Irvin",
status: "Cancelled",
unitary_price: 50,
seats: 1
}, {
name: "Ricardo",
status: "Active",
unitary_price: 50,
seats: 3
}, {
name: "Irvin",
status: "Active",
unitary_price: 50,
seats: 1
}, {
name: "Sebastian",
status: "Cancelled",
unitary_price: 25,
seats: 4
}];
var saldo = 0;
ejer2.forEach(function (arr) {
if(arr.status === "Cancelled"){
saldo += arr.unitary_price*arr.seats;
}
});
console.log("Total de saldo", saldo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment