|
| 1 | +// Sección de declaraciones, NO EDITAR |
| 2 | + |
| 3 | +// Responsables de los cuarteles |
| 4 | +const paddockManagers = [ |
| 5 | + { id: 1, taxNumber: '132254524', name: 'JUAN TAPIA BURGOS'}, |
| 6 | + { id: 2, taxNumber: '143618668', name: 'EFRAIN SOTO VERA'}, |
| 7 | + { id: 3, taxNumber: '78903228', name: 'CARLOS PEREZ GONZALEZ'}, |
| 8 | + { id: 4, taxNumber: '176812737', name: 'ANDRES VIÑALES CIENFUEGOS'}, |
| 9 | + { id: 5, taxNumber: '216352696', name: 'OSCAR PEREZ ZUÑIGA'}, |
| 10 | + { id: 6, taxNumber: '78684747', name: 'JOAQUIN ANDRADE SANDOVAL' } |
| 11 | +]; |
| 12 | + |
| 13 | +// Tipo de cuartel, en el cual se utiliza el tipo de producto plantado |
| 14 | +const paddockType = [ |
| 15 | + { id: 1, name: 'PALTOS' }, |
| 16 | + { id: 2, name: 'AVELLANOS' }, |
| 17 | + { id: 3, name: 'CEREZAS' }, |
| 18 | + { id: 4, name: 'NOGALES' }, |
| 19 | +] |
| 20 | + |
| 21 | +// Un paddock representa un cuartel de un campo (Entiéndase también como potrero o parcela), el área está representada en m2, harvestYear es el año en el que se sembró el cuartel |
| 22 | +const paddocks = [ |
| 23 | + { paddockManagerId: 6, farmId: 1, paddockTypeId: 1, harvestYear: 2019, area: 1200 }, |
| 24 | + { paddockManagerId: 1, farmId: 3, paddockTypeId: 4, harvestYear: 2019, area: 500 }, |
| 25 | + { paddockManagerId: 5, farmId: 3, paddockTypeId: 2, harvestYear: 2020, area: 20000 }, |
| 26 | + { paddockManagerId: 2, farmId: 2, paddockTypeId: 3, harvestYear: 2021, area: 8401}, |
| 27 | + { paddockManagerId: 3, farmId: 1, paddockTypeId: 1, harvestYear: 2020, area: 2877 }, |
| 28 | + { paddockManagerId: 5, farmId: 2, paddockTypeId: 2, harvestYear: 2017, area: 15902 }, |
| 29 | + { paddockManagerId: 3, farmId: 3, paddockTypeId: 2, harvestYear: 2018, area: 1736 }, |
| 30 | + { paddockManagerId: 2, farmId: 3, paddockTypeId: 3, harvestYear: 2020, area: 2965 }, |
| 31 | + { paddockManagerId: 4, farmId: 3, paddockTypeId: 4, harvestYear: 2018, area: 1651 }, |
| 32 | + { paddockManagerId: 5, farmId: 1, paddockTypeId: 1, harvestYear: 2018, area: 700 }, |
| 33 | + { paddockManagerId: 1, farmId: 2, paddockTypeId: 1, harvestYear: 2019, area: 7956 }, |
| 34 | + { paddockManagerId: 5, farmId: 3, paddockTypeId: 2, harvestYear: 2020, area: 3745 }, |
| 35 | + { paddockManagerId: 6, farmId: 1, paddockTypeId: 3, harvestYear: 2021, area: 11362 }, |
| 36 | + { paddockManagerId: 2, farmId: 3, paddockTypeId: 3, harvestYear: 2021, area: 300 }, |
| 37 | + { paddockManagerId: 3, farmId: 2, paddockTypeId: 2, harvestYear: 2020, area: 19188 }, |
| 38 | + { paddockManagerId: 3, farmId: 1, paddockTypeId: 1, harvestYear: 2019, area: 17137 }, |
| 39 | + { paddockManagerId: 4, farmId: 3, paddockTypeId: 2, harvestYear: 2020, area: 100 }, |
| 40 | + { paddockManagerId: 2, farmId: 1, paddockTypeId: 3, harvestYear: 2019, area: 11845 }, |
| 41 | + { paddockManagerId: 5, farmId: 2, paddockTypeId: 1, harvestYear: 2018, area: 15969 }, |
| 42 | + { paddockManagerId: 1, farmId: 3, paddockTypeId: 1, harvestYear: 2029, area: 10420 }, |
| 43 | + { paddockManagerId: 5, farmId: 2, paddockTypeId: 3, harvestYear: 2010, area: 3200 }, |
| 44 | + { paddockManagerId: 6, farmId: 1, paddockTypeId: 2, harvestYear: 2012, area: 10587 }, |
| 45 | + { paddockManagerId: 2, farmId: 2, paddockTypeId: 2, harvestYear: 2018, area: 16750 } |
| 46 | +]; |
| 47 | + |
| 48 | +const farms = [ |
| 49 | + { id: 1, name: 'AGRICOLA SANTA ANA' }, |
| 50 | + { id: 2, name: 'VINA SANTA PAULA' }, |
| 51 | + { id: 3, name: 'FORESTAL Y AGRICOLA LO ENCINA' } |
| 52 | +]; |
| 53 | + |
| 54 | +/* |
| 55 | + SECCIÓN PROBLEMAS |
| 56 | +*/ |
| 57 | +// Tip: Una hectárea equivale a 10.000m2 |
| 58 | + |
| 59 | +// 0 Arreglo con los ids de los responsables de cada cuartel |
| 60 | +function listPaddockManagerIds() { |
| 61 | + return paddockManagers.map((paddockManager) => paddockManager.id); |
| 62 | +}; |
| 63 | + |
| 64 | +// 1 Arreglo con los ruts de los responsables de los cuarteles, ordenados por nombre |
| 65 | +/* function listPaddockManagersByName() { |
| 66 | + paddockManagers.sort((a,b) =>parseInt(a.taxNumber) - parseInt(b.taxNumber)); |
| 67 | + return paddockManagers.map((element) => element.taxNumber); |
| 68 | +}; |
| 69 | + */ |
| 70 | + |
| 71 | +// Supuesto: Orden alfabético ascendente |
| 72 | +function listPaddockManagersByName() { |
| 73 | +return paddockManagers.sort((a,b) => a.name.localeCompare(b.name)).map(e => e.taxNumber) |
| 74 | +}; |
| 75 | + |
| 76 | + |
| 77 | +// 2 Arreglo con los nombres de cada tipo de cultivo, ordenados decrecientemente por la suma TOTAL de la cantidad de hectáreas plantadas de cada uno de ellos. |
| 78 | +function sortPaddockTypeByTotalArea() { |
| 79 | +return paddockType.map(paddockTypes => { |
| 80 | + let totalArea = 0; |
| 81 | + paddocks.forEach(paddocksItem =>(paddocksItem.paddockTypeId == paddockTypes.id) ? totalArea = totalArea + paddocksItem.area : '') |
| 82 | + return { name: paddockTypes.name, area:totalArea }; |
| 83 | + }).sort((a,b) => b.area - a.area).map((paddockTypes) => paddockTypes.name) } |
| 84 | + |
| 85 | + |
| 86 | +// 3 Arreglo con los nombres de los administradores, ordenados decrecientemente por la suma TOTAL de hectáreas que administran. |
| 87 | +function sortFarmManagerByAdminArea() { |
| 88 | + return paddockManagers.map(paddockManager => { |
| 89 | + let totalArea = 0; |
| 90 | + paddocks.forEach(paddocksItem =>(paddocksItem.paddockManagerId == paddockManager.id) ? totalArea = totalArea + paddocksItem.area : '') |
| 91 | + return { name: paddockManager.name, area:totalArea }; |
| 92 | + }).sort((a,b) => b.area - a.area).map((paddockManager) => paddockManager.name) } |
| 93 | + |
| 94 | + |
| 95 | +// 4 Objeto en que las claves sean los nombres de los campos y los valores un arreglo con los ruts de sus administradores ordenados alfabéticamente por nombre. |
| 96 | +function farmManagerNames() { |
| 97 | + // CODE HERE |
| 98 | +} |
| 99 | + |
| 100 | +// 5 Arreglo ordenado decrecientemente con los m2 totales de cada campo que tengan más de 2 hectáreas en Paltos |
| 101 | +function biggestAvocadoFarms() { |
| 102 | + // CODE HERE |
| 103 | +} |
| 104 | + |
| 105 | +// 6 Arreglo con nombres de los administradores de la FORESTAL Y AGRÍCOLA LO ENCINA, ordenados por nombre, que trabajen más de 1000 m2 de Cerezas |
| 106 | +function biggestCherriesManagers() { |
| 107 | + // CODE HERE |
| 108 | +} |
| 109 | + |
| 110 | +// 7 Objeto en el cual las claves sean el nombre del administrador y el valor un arreglo con los nombres de los campos que administra, ordenados alfabéticamente |
| 111 | +function farmManagerPaddocks() { |
| 112 | + // CODE HERE |
| 113 | +} |
| 114 | + |
| 115 | +// 8 Objeto en que las claves sean el tipo de cultivo concatenado con su año de plantación (la concatenación tiene un separador de guión ‘-’, por ejemplo AVELLANOS-2020) y el valor otro objeto en el cual la clave sea el id del administrador y el valor el nombre del administrador |
| 116 | +function paddocksManagers() { |
| 117 | + // CODE HERE |
| 118 | +} |
| 119 | + |
| 120 | +// 9 Agregar nuevo administrador con datos ficticios a "paddockManagers" y agregar un nuevo cuartel de tipo NOGALES con 900mts2, año 2017 de AGRICOLA SANTA ANA, administrado por este nuevo administrador |
| 121 | +// Luego devolver el lugar que ocupa este nuevo administrador en el ranking de la pregunta 3. |
| 122 | +// No modificar arreglos originales para no alterar las respuestas anteriores al correr la solución |
| 123 | +function newManagerRanking() { |
| 124 | + // CODE HERE |
| 125 | +} |
| 126 | + |
| 127 | + |
| 128 | +// No modificar, eliminar o alterar cualquier línea de código o comentario de acá para abajo |
| 129 | +// Cualquier cambio hará que su prueba quede invalidada automáticamente |
| 130 | +console.log('Pregunta 0'); |
| 131 | +console.log(listPaddockManagerIds()); |
| 132 | +console.log('Pregunta 1'); |
| 133 | +console.log(listPaddockManagersByName()); |
| 134 | +console.log('Pregunta 2'); |
| 135 | +console.log(sortPaddockTypeByTotalArea()); |
| 136 | +console.log('Pregunta 3'); |
| 137 | +console.log(sortFarmManagerByAdminArea()); |
| 138 | +console.log('Pregunta 4'); |
| 139 | +console.log(farmManagerNames()); |
| 140 | +console.log('Pregunta 5'); |
| 141 | +console.log(biggestAvocadoFarms()); |
| 142 | +console.log('Pregunta 6'); |
| 143 | +console.log(biggestCherriesManagers()); |
| 144 | +console.log('Pregunta 7'); |
| 145 | +console.log(farmManagerPaddocks()); |
| 146 | +console.log('Pregunta 8'); |
| 147 | +console.log(paddocksManagers()); |
| 148 | +console.log('Pregunta 9'); |
| 149 | +console.log(newManagerRanking()); |
0 commit comments