project: testing (#15)

This commit is contained in:
Smigz 2024-02-16 16:07:49 -05:00 committed by GitHub
parent 6f8a4ec879
commit d899a773bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 9544 additions and 0 deletions

42
testing/src/odinTests.js Normal file
View file

@ -0,0 +1,42 @@
const capitalize = (thing) => thing.charAt(0).toUpperCase() + thing.slice(1);
const reverseString = (thing) => thing.split('').reverse().join('');
const calculator = (a, b, operation) => {
switch (operation) {
case '+':
return a + b;
case '-':
return a - b;
case '*':
return a * b;
case '/':
if (b === 0) {
return 'error';
}
return a / b;
}
};
const ceaserCipher = (thing) => {
let cipher = thing.split('').map((item) => {
let charCode = item.charCodeAt(0);
return String.fromCharCode(charCode + 3);
});
return cipher.join('');
};
const analyzeArray = (arr) => {
let min = Math.min(...arr);
let max = Math.max(...arr);
let length = arr.length;
let avg = arr.reduce((sum, num) => sum + num, 0) / length;
return {
average: avg,
min: min,
max: max,
length: length,
};
};
export { analyzeArray, ceaserCipher, calculator, capitalize, reverseString };