From f4f7dd7594b55c8b24db7c6ee1d6a04d1d1bd829 Mon Sep 17 00:00:00 2001 From: angel Date: Mon, 27 Oct 2025 11:49:26 -0500 Subject: [PATCH] fdsa --- .hintrc | 13 ++++++++ BinarySearch.js | 11 +++++++ LabArrays1.js | 62 +++++++++++++++++++++++++++++++++++++ LabArrays2.js | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ mrmundo.js | 63 +++++++++++++++++++++++++++++++++++++ 5 files changed, 231 insertions(+) create mode 100644 .hintrc create mode 100644 BinarySearch.js create mode 100644 LabArrays1.js create mode 100644 LabArrays2.js create mode 100644 mrmundo.js diff --git a/.hintrc b/.hintrc new file mode 100644 index 0000000..5b02c11 --- /dev/null +++ b/.hintrc @@ -0,0 +1,13 @@ +{ + "extends": [ + "development" + ], + "hints": { + "axe/forms": [ + "default", + { + "label": "off" + } + ] + } +} \ No newline at end of file diff --git a/BinarySearch.js b/BinarySearch.js new file mode 100644 index 0000000..ebf6175 --- /dev/null +++ b/BinarySearch.js @@ -0,0 +1,11 @@ + + +// Searching algorithm: Binary search +// Write function bSearch so that it return the location of target if +// it is found in array list. If target is not found bSearch returns -1 +function bSearch(list, target) +{ +} + +// use the following array to test your function +let arr = ["Allegator", "Bee", "Bull", "dog", "Ferret", "Tiger", "zebra"] \ No newline at end of file diff --git a/LabArrays1.js b/LabArrays1.js new file mode 100644 index 0000000..3a66b38 --- /dev/null +++ b/LabArrays1.js @@ -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'); \ No newline at end of file diff --git a/LabArrays2.js b/LabArrays2.js new file mode 100644 index 0000000..a1bcee6 --- /dev/null +++ b/LabArrays2.js @@ -0,0 +1,82 @@ + +// humberto mundo + + + +// Objective: shift() and push() +// Write a function named circulate(list). This function takes an array as parameter and +// returns the same array but the elements move up one spot. For example, say the +// array is ["Zebra", "Koala", "Lion", "Elephan", "Eagle", "Cat", "Eagle"], circulate will +// return ["Eagle", "Zebra", "Koala", "Lion", "Elephant", "Eagle", "Cat"] +let array1 = ["Zebra", "Koala", "Lion", "Elephant", "Eagle", "Cat", "Eagle"] + +function circulate(list) { + if (list.length === 0 ) return []; // since if length of the arry is 0 return nothing + const lastElement = list.pop(); + list.unshift(lastElement); + return list; +} + +console.log(circulate(array1)) + +console.log() +console.log() + +// Objective: slice(1, 5) +// Write a function named getHalf(). This function takes an array as a parameter and copies +// the first half of an array and returns it. if the the array contains odd number of elements, +// the middle element should belong to the first half. +// For example ["Zebra", "Koala", "Lion", "Elephan", "Eagle", "Cat", "Eagle"], this function +// return ["Zebra", "Koala", "Lion", "Elephant"] + +let array2 = ["Zebra", "Koala", "Lion", "Elephant", "Eagle", "Cat", "Eagle"]; + +function getHalf(list) { + if (list.length === 1) return list + // docs say Math.ceil() "returns the smallest integer greater than or equal to its number argument " in short terms rounds ups the number + return list.slice(0, Math.round(list.length / 2)) +} + +console.log(getHalf(array2)) + +console.log() +console.log() + +// Write a function named removeDuplicates(). This function takes an array as a parameter, removes, +// all duplicates and returns the new array (without duplicates) +// For example ["Lion", "Koala", "Lion", "Elephan", "Eagle", "Cat", "CAT"], this function +// return ["Lion", "Koala", "Elephant", "Eagle", "Cat"], + +let array3 = ["Lion", "Koala", "Lion", "Elephant", "Eagle", "Cat", "CAT"] + +function removeDuplicates(list) { + let seen = new Set(); // create new collection + for (let i = 0; i < list.length; i++) { + let item = list[i] + // console.log(!seen.has(item)) + if(!seen.has(item.toLowerCase())) { + seen.add(item.toLowerCase()) // add to new collection + list.splice(list.indexOf(item), list.indexOf(item)) + // console.log(`added ${item.toLowerCase()}`) + } + } + return list +} + +console.log(removeDuplicates(array3)) + +console.log() +console.log() +// Write a function named sortNames(). This function takes an array as a parameter, +// and returns a new array but with names sorted in ascending order +// For example say list = ["Lion", "Cat", "Zebra", "Eagle", "Elephan", "Koala"], the +// folowing call sortNames(list) will return +// ["Cat", "Eagle", "Elephan", "Koala", "Lion", "Zebra"] + +let array4 = ["Lion", "Cat", "Zebra", "Eagle", "Elephan", "Koala"] + +function sortNames(list) { + return list.sort() +} + +console.log(sortNames(array4)) diff --git a/mrmundo.js b/mrmundo.js new file mode 100644 index 0000000..8adcfb2 --- /dev/null +++ b/mrmundo.js @@ -0,0 +1,63 @@ +// 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