Skip to content

Commit

Permalink
Merge pull request #2882 from marcode24/challenge-14
Browse files Browse the repository at this point in the history
Reto #14 - Javascript
  • Loading branch information
mouredev authored Apr 4, 2023
2 parents fa813fe + c1b1757 commit 3280fbd
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Crea una función que reciba un número decimal y lo trasforme a Octal
* y Hexadecimal.
* - No está permitido usar funciones propias del lenguaje de programación que
* realicen esas operaciones directamente.
*/

const convertToOctal = (number) => {
let octal = '';
while (number > 0) {
const rest = number % 8;
octal = rest + octal;
number = Math.floor(number / 8);
}

return octal;
};

const convertToHexadecimal = (number) => {
let hexadecimal = '';
while (number > 0) {
const remainder = number % 16;
const char = remainder < 10 ? remainder : String.fromCharCode(remainder + 55);
hexadecimal = char + hexadecimal;
number = Math.floor(number / 16);
}
return hexadecimal;
};

const convertToHexadecimalAndOctal = (number) => ({
octal: convertToOctal(number),
hexadecimal: convertToHexadecimal(number),
});

// Visita mi repo en GitHub para ver y correr los tests de este código --> https://github.com/marcode24/weekly-challenges

0 comments on commit 3280fbd

Please sign in to comment.