fdsa
This commit is contained in:
62
LabArrays1.js
Normal file
62
LabArrays1.js
Normal file
@@ -0,0 +1,62 @@
|
||||
// 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) {
|
||||
return list.indexOf(word);
|
||||
}
|
||||
|
||||
// Write a function named getLongest(list) which needs to return the longest string in array
|
||||
// parameter array
|
||||
|
||||
function getLongest(array) {
|
||||
if (!array) return "provide a array";
|
||||
|
||||
let longest = array[0]
|
||||
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
if (array[i].length > longest.length) {
|
||||
long = array[i];
|
||||
}
|
||||
}
|
||||
return long
|
||||
}
|
||||
|
||||
|
||||
// // 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) == -1) 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');
|
||||
Reference in New Issue
Block a user