Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solución Reto #34 JavaScript #681

Open
YlichLayana opened this issue Aug 24, 2022 · 0 comments
Open

Solución Reto #34 JavaScript #681

YlichLayana opened this issue Aug 24, 2022 · 0 comments

Comments

@YlichLayana
Copy link

YlichLayana commented Aug 24, 2022

Solución creada en lenguaje JS usando dos funciones.

Podrían ayudarme con los pasos correctos para poder realizar el Pull requests de mi solución

//función para saber si esta ordenado el array recibido
function arrayIsOrden(datos) {
let result = true;
for (let i = 0; i < datos.length; i++) {
if (datos[i] <= datos[i - 1]) {
result = false;
break;
}
}
return result;
}

//función principal para determinar que números faltantes del array recibido
function numsFaltantes(datosRecibidos) {
let contador = 0;
let numsFaltntes = [];
let resultado = "Error: el dato recibido no es un array valido";

if (Array.isArray(datosRecibidos) && datosRecibidos.length >= 2 && arrayIsOrden(datosRecibidos)) {
let ultimoElemento = datosRecibidos[datosRecibidos.length - 1];
let primerElemento = datosRecibidos[0];

for (var i = primerElemento; i <= ultimoElemento; i++) {
  if (!datosRecibidos.includes(i)) {
    contador++;
    numsFaltntes.push(i);
    if (contador > 1) {
      resultado = numsFaltntes;
    } else {
      resultado = i;
    }
  }
}

}

return resultado;
}

console.log(numsFaltantes([1, 3]));
console.log(numsFaltantes([0, 2, 3]));
console.log(numsFaltantes([5, 6, 1, 2, 3, 7, 0]));
console.log(numsFaltantes([3, 0, 1]));
console.log(numsFaltantes([1, 2, 3, 5, 6, 7, 10, 15]));
console.log(numsFaltantes([1, 2, 5]));

@YlichLayana YlichLayana changed the title Solución Reto 3 Solución Reto #34 JavaScript Aug 24, 2022
@YlichLayana YlichLayana reopened this Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant