63 lines
2.1 KiB
JavaScript
63 lines
2.1 KiB
JavaScript
// ram usage test to see what is better mines or mr mundo's
|
|
|
|
const memoryUsage = process.memoryUsage();
|
|
|
|
|
|
// humberto mundo
|
|
let animals = ["Zebra", "Koala", "Lion", "Elephant", "Eagle", "Cat", "Eagle"]
|
|
|
|
|
|
// Write a function named getLocation(list, word) to return the location of the parameter word
|
|
// in the array list, if it exist, returns -1 if it does not exists
|
|
|
|
function getLocation(list, word) {
|
|
let loc = 0;
|
|
let found = false
|
|
let pos = 0
|
|
while (pos<list.length && found ==false) {
|
|
if (word==list[pos]) {
|
|
found = true;
|
|
loc = pos;
|
|
}
|
|
pos++
|
|
}
|
|
return loc
|
|
}
|
|
|
|
// Write a function named getLongest(list) which needs to return the longest string in array
|
|
// parameter array
|
|
|
|
// function getLongest(array) {
|
|
|
|
// }
|
|
|
|
|
|
// // Write a function named spellBackward(list, word) which it needs to return parameter word
|
|
// // spell backwards if it exist in array list, otherwise it return word does not exist.
|
|
|
|
// function spellBackward(list, word) {
|
|
// if (!getLocation(list, word)) return 'word does not exist'
|
|
// return word.split("").reverse().join("")
|
|
// }
|
|
|
|
|
|
//write the rest of the code here
|
|
|
|
console.log(getLocation(animals, "Eagle")); // uhhhh 4
|
|
// console.log(getLocation(animals, "cat")); // should return -1 since its Cat not cat
|
|
// console.log(); // spacers
|
|
// console.log(getLongest(animals)); // Elephant
|
|
// console.log(); // spacers
|
|
// // i am the best programmer in the world
|
|
// console.log(spellBackward(animals, "Eagle")); // should return elgaE
|
|
// console.log(spellBackward(animals, "cat")); // should return "word does not exist"
|
|
|
|
|
|
console.log('Memory Usage (bytes):', memoryUsage);
|
|
|
|
// To get specific metrics, you can access the properties:
|
|
console.log('Resident Set Size (RSS):', memoryUsage.rss / (1024 * 1024), 'MB');
|
|
console.log('Heap Total:', memoryUsage.heapTotal / (1024 * 1024), 'MB');
|
|
console.log('Heap Used:', memoryUsage.heapUsed / (1024 * 1024), 'MB');
|
|
console.log('External:', memoryUsage.external / (1024 * 1024), 'MB');
|
|
console.log('Array Buffers:', memoryUsage.arrayBuffers / (1024 * 1024), 'MB'); |