-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e95c164
commit 14c956c
Showing
2 changed files
with
22 additions
and
10 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,21 +1,33 @@ | ||
const numerosPalidromos = []; | ||
function palindromos(min, max) { | ||
if (min < 1 || max < 1) { | ||
for (; min <= max; min++) { | ||
const numInverso = +min.toString().split("").reverse().join(""); | ||
if (min === numInverso) { | ||
numerosPalidromos.push(min); | ||
} | ||
} | ||
return numerosPalidromos; | ||
} | ||
|
||
function verificacao(min, max) { | ||
if (typeof min !== "number" || typeof max !== "number") { | ||
console.log("Coloque apenas valores númericos"); | ||
return; | ||
} else if (min < 1 || max < 1) { | ||
console.log("Adicione apenas valores positivos ou maior que 0"); | ||
return; | ||
} else if (min >= max) { | ||
console.log( | ||
"O valor mínimo não pode ser maior ou igual ao valor máximo" | ||
); | ||
return; | ||
} else if (!(Number.isInteger(min) && Number.isInteger(max))) { | ||
console.log("Adicione apenas números inteiros"); | ||
return; | ||
} else { | ||
for (; min <= max; min++) { | ||
const numInverso = +min.toString().split("").reverse().join(""); | ||
if (min === numInverso) { | ||
numerosPalidromos.push(min); | ||
} | ||
} | ||
palindromos(min, max); | ||
} | ||
} | ||
palindromos(1, 100); | ||
|
||
verificacao(1, 200); //valores apenas para exemplo | ||
console.log(numerosPalidromos); |