fdsa
This commit is contained in:
13
.hintrc
Normal file
13
.hintrc
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
"development"
|
||||||
|
],
|
||||||
|
"hints": {
|
||||||
|
"axe/forms": [
|
||||||
|
"default",
|
||||||
|
{
|
||||||
|
"label": "off"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
11
BinarySearch.js
Normal file
11
BinarySearch.js
Normal file
@@ -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"]
|
||||||
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');
|
||||||
82
LabArrays2.js
Normal file
82
LabArrays2.js
Normal file
@@ -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))
|
||||||
63
mrmundo.js
Normal file
63
mrmundo.js
Normal file
@@ -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<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');
|
||||||
Reference in New Issue
Block a user