-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modificação no código atribuindo a verificação aos valores que são pa…
…ssados e mensagem derro, adição de etapa no README
- Loading branch information
1 parent
d589f50
commit a601157
Showing
2 changed files
with
21 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
let numerosPalidromos = []; | ||
const numerosPalidromos = []; | ||
function palindromos(min, max) { | ||
for (; min <= max; min++) { | ||
const numInverso = min.toString().split("").reverse().join(""); | ||
if (min == numInverso) { | ||
numerosPalidromos.push(min); | ||
if (min < 1 || max < 1) { | ||
console.log("Adicione apenas valores positivos ou maior que 0"); | ||
} else if (min >= max) { | ||
console.log( | ||
"O valor mínimo não pode ser maior ou igual ao valor máximo" | ||
); | ||
} else if (!(Number.isInteger(min) && Number.isInteger(max))) { | ||
console.log("Adicione apenas números inteiros"); | ||
} else { | ||
for (; min <= max; min++) { | ||
const numInverso = +min.toString().split("").reverse().join(""); | ||
if (min === numInverso) { | ||
numerosPalidromos.push(min); | ||
} | ||
} | ||
} | ||
} | ||
palindromos(1, 2000); | ||
palindromos(1.1, 100); | ||
console.log(numerosPalidromos); |