Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Algorithms/BMI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function BMI(mass, height) {
let BMI = mass / height ** 2;
console.log('Your Body Mass Index: ' + BMI);

if (BMI < 17)
console.log('Very underweight');
else if (BMI < 18.5)
console.log('Underweight');
else if (BMI < 25)
console.log('Normal weight');
else if (BMI < 30)
console.log('Overweight');
else if (BMI < 35)
console.log('obesity I');
else if (BMI < 40)
console.log('obesity II (Several)');
else
console.log('obesity III (Morbid)');
}

(function main() {
BMI(63, 1.71);
BMI(73, 1.72);
BMI(83, 1.73);
BMI(93, 1.74);
})();
49 changes: 49 additions & 0 deletions Algorithms/binarySystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class binarySystem {
convertToBinary(text = '') {
let final = '';
for (let i = 0; i < text.length; i++) {
let binary = '', result = '', number = text.charCodeAt(i);

while (number != 0) {
binary += number % 2;
number /= 2;
number = parseInt(number);
}

let length = binary.length;
if (length < 8)
for (let i = 0; i < 8 - length; i++)
binary += '0';

for (let i = binary.length - 1; i >= 0; i--)
result += binary[i];

final += result + ' ';
}

return final.trim();
}

convertToText(binary = '') {
let text = [], binaryCode = binary.split(' ');
for (let i = 0; i < binaryCode.length; i++) {
let qtd = 0, atual = 0;
for (let j = binaryCode[i].length - 1; j >= 0; j--) {
if (binaryCode[i][j] == '1')
qtd += 2 ** atual;
atual++;
}

text.push(qtd);
}

return String.fromCharCode(...text);
}
}

let system = new binarySystem();

(function main() {
system.convertToBinary('Algorithm');
system.convertToText('01000001 01101100 01100111 01101111 01110010 01101001 01110100 01101000 01101101');
})();
11 changes: 11 additions & 0 deletions Algorithms/binarySystemMinimal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class binarySystemMinimal {
convertToBinary(text) { console.log(text.split('').map(letter => letter.charCodeAt(0).toString(2)).join(' ')); }
convertToText(binary) { console.log(binary.split(' ').map(binaryCode => String.fromCharCode(parseInt(binaryCode, 2))).join('')); }
}

let systemMinimal = new binarySystemMinimal();

(function main() {
systemMinimal.convertToBinary('Lucas');
systemMinimal.convertToText('1001100 1110101 1100011 1100001 1110011');
})();
15 changes: 15 additions & 0 deletions Algorithms/primeNumbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function primeNumber(number) {
let qtdDiv = 0;
for (let i = number; i > 0; i--)
if (number % i == 0)
qtdDiv++;

return qtdDiv == 2 ? "It's a Prime number!" : 'Not is a prime number!';
}

(function main() {
console.log(primeNumber(5));
console.log(primeNumber(6));
console.log(primeNumber(7));
console.log(primeNumber(8));
})();
12 changes: 12 additions & 0 deletions Algorithms/reverseString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function stringInvert(str) {
let strInverted = '';
for (let i = str.trim().length - 1; i >= 0; i--)
strInverted += str.trim()[i];

console.log('Inverted text: ' + strInverted);
}

(function main() {
stringInvert('Algorithm');
stringInvert('mhtiroglA');
})();