Compare commits

10 Commits

Author SHA1 Message Date
53cdaa3037 Upload files to "lab" 2025-10-27 12:26:29 -05:00
6083fced21 Upload files to "arrays" 2025-10-27 12:26:12 -05:00
ef28aafda1 Upload files to "arrays" 2025-10-27 12:26:06 -05:00
3683031350 Update README.md 2025-10-27 12:25:44 -05:00
c171af84c1 Upload files to "/" 2025-10-27 11:50:19 -05:00
441c290663 Upload files to "/" 2025-10-27 11:50:13 -05:00
a383913b42 Upload files to "/" 2025-10-27 11:50:03 -05:00
bccb3378c6 Upload files to "/" 2025-10-27 11:49:53 -05:00
b0aabb32c8 Upload files to "/" 2025-10-27 11:49:47 -05:00
f4f7dd7594 fdsa 2025-10-27 11:49:26 -05:00
39 changed files with 1642 additions and 3 deletions

13
.hintrc Normal file
View File

@@ -0,0 +1,13 @@
{
"extends": [
"development"
],
"hints": {
"axe/forms": [
"default",
{
"label": "off"
}
]
}
}

11
BinarySearch.js Normal file
View 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"]

30
BinarySearch.ts Normal file
View File

@@ -0,0 +1,30 @@
// 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: string[], target: string) {
let left = 0
let right = list.length - 1
while (left <= right) {
let mid = Math.floor((left + right) / 2)
if (list[mid] === target) {
return mid
}
if (list[mid]! < target) {
left = mid + 1
} else {
right = mid - 1
}
}
return -1
}
// use the following array to test your function
let arr = ["Allegator", "Bee", "Bull", "Dog", "Ferret", "Tiger", "Zebra"] // already sorted a-z
console.log("Zebra was at location " + bSearch(arr, "Zebra"))
console.log("Bee was at location " + bSearch(arr, "Bee"))
console.log("Allegator was at location " + bSearch(arr, "Allegator"))

62
LabArrays1.js Normal file
View 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
View 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))

82
LabArrays2.ts Normal file
View 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: string[] = ["Zebra", "Koala", "Lion", "Elephant", "Eagle", "Cat", "Eagle"]
function circulate(list: string[]) {
if (list.length === 0 ) return []; // since if length of the arry is 0 return not
const lastElement = list.pop()!;
list.unshift(lastElement);
return list;
}
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: string[] = ["Zebra", "Koala", "Lion", "Elephant", "Eagle", "Cat", "Eagle"];
function getHalf(list: string[]) {
return list.slice(0, Math.ceil(list.length / 2))
}
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: string[] = ["Lion", "Koala", "Lion", "Elephant", "Eagle", "Cat", "CAT"]
function removeDuplicates(list: string[]) {
let seen = new Set<string>();
// let newarray: string[] = [];
for (let i = 0; i < list.length; i++) {
let item: string = list[i]!
// console.log(!seen.has(item))
if(!seen.has(item.toLowerCase())) {
seen.add(item.toLowerCase())
list.splice(list.indexOf(item), list.indexOf(item))
// console.log(`added ${item.toLowerCase()}`)
}
}
return list
}
console.log(removeDuplicates(array3))
// want [ 'Lion', 'Koala', 'Elephant', 'Eagle', 'Cat' ]
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: string[] = ["Lion", "Cat", "Zebra", "Eagle", "Elephan", "Koala"]
function sortNames(list: string[]) {
return list.sort()
}

BIN
Programmig test.docx Normal file

Binary file not shown.

View File

@@ -1,3 +1 @@
# AP-Computer-Science-Stuff
read the top?!
ap computer principles archive for each quauter cus im not having many devices on google drive

27
StockBehavior.js Normal file
View File

@@ -0,0 +1,27 @@
//The array stocks stores the behavior of stocks for one year.
//The numbers in the array represent percentages.
let stocks = [ 5, 5,5,5]
//A peak is when the percentage on the left of a given month M is less and the
//percentage on the right of month M is greater. For example, the list given above, contains
//three peaks, they are 6, 8, and 10 (positions 1, 5 and 9 respectively)
// Complete function getPeaks so that it returns an array containing all the locations
// of all peaks that a exists in the parameter array named list.
// If there are no peaks, this function should return an empty array ([])
function getPeaks(list){
let finishedarray = [];
for (let i = 0; i < list.length-1; i++) {
// console.log(`i is ${i}, arrindex is ${list[i]}, before, ${list[i-1]}, after ${list[i+1]}`)
if (list[i] > list[i - 1] && list[i] > list[i+1] ) {
finishedarray.push(i);
}
}
return finishedarray;
}
// for the array stocks shown above, getPeaks should return [1, 5, 9]
// WRITE CODE TO TEST YOUR FUNCTION HERE.
console.log(getPeaks(stocks))

27
StockBehavior.ts Normal file
View File

@@ -0,0 +1,27 @@
//The array stocks stores the behavior of stocks for one year.
//The numbers in the array represent percentages.
let stocks = [ 5, 6, 3, 4, 5, 8, 5, 3, 2, 10, 9, 5]
//A peak is when the percentage on the left of a given month M is less and the
//percentage on the right of month M is greater. For example, the list given above, contains
//three peaks, they are 6, 8, and 10 (positions 1, 5 and 9 respectively)
// Complete function getPeaks so that it returns an array containing all the locations
// of all peaks that a exists in the parameter array named list.
// If there are no peaks, this function should return an empty array ([])
function getPeaks(list: number[]){
let finishedarray: number[] = [];
for (let i = 0; i < list.length-1; i++) {
// console.log(`i is ${i}, arrindex is ${list[i]}, before, ${list[i-1]}, after ${list[i+1]}`)
if (list[i]! > list[i - 1]! && list[i]! > list[i+1]!) {
finishedarray.push(i);
}
}
return finishedarray;
}
// for the array stocks shown above, getPeaks should return [1, 5, 9]
// WRITE CODE TO TEST YOUR FUNCTION HERE.
console.log(getPeaks(stocks))

15
StringChallenge.ts Normal file
View File

@@ -0,0 +1,15 @@
function fizzBuzz(n: number): string[] {
let h = []
for (let i=1; i<=n;i++) {
let string = ''
if (i % 3 === 0){
string += 'Fizz'
} else if (i % 5 === 0) {
string += 'Buzz'
} else if (string === '') {
string += i
}
h.push(string)
}
return h
};

56
StringChanllenge.js Normal file
View File

@@ -0,0 +1,56 @@
/*
QUOTE: I have a dream that my four little children will one day live
in a nation where they will not be judged by the color of
their skin but by the content of their character.
*/
let meow = "I have a dream that my four little children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character."
// Function getFrequency takes as parameters two strings, text and token.
// This function needs to return the number of times a token accurs in text
// For example, if this function is tested with above quote and token is
// "will", then this function should return 2 becuase "will" occurs twice in
// the text
function getFrequency(text, token) {
let count = 0;
let words = text.split(" "); // Changed from text.split("")
for (let i=0; i<words.length; i++) {
let word=words[i]
if (word === token) {
count++;
}
}
return count;
}
console.log(getFrequency(meow, "will"));
// Function search takes as parameters two strings, text and token.
// This function needs to return the location where token occurs
// in parameter text. For example, if you call this function with
// token = "dream", this function will return 9. If token does not exist
// in text this function should return -1
function search(text, token){
return text.indexOf(token)
}
console.log(search(meow, "dream"))
// Function spellWord takes as parameters two strings, text and word.
// This function needs to return a spell of parameter word. For example,
// if you call this function with token = "children", this function should
// return c,h,i,l,d,r,e,n
// If word does not exist in text, this function should return "Word not found"
function spellWord(text, word) {
const words = text.split(" ").filter(s => s.length > 0);
const lowercaseWords = words.map(w => w.toLowerCase());
const lowerCaseWord = word.toLowerCase();
if (lowercaseWords.includes(lowerCaseWord)) {
return word.split("").join(",");
} else {
return "Word not found";
}
}
console.log(spellWord(meow, "children"))
// write code to test your functions

91
Untitled-1.ts Normal file
View File

@@ -0,0 +1,91 @@
// NOTE: YOUR ARE NOT ALLOWED TO USE EXISTING FUNCTION FROM
// THE JAVASCRIPT LIBRARY TO SORT ARRAYS. NOT CREDIT WILL BE
// GIVEN IF YOU DO
// Function findSopt() takes two parameters an array of strings name list and
// a string named target. Array list contains strings storing country names sorted
// in ascending order and target contains the name of a country. Write code so
// that findSpot returns the location where targer fits alphabetically in the list
// of countries.
// For example, if list is ["Australia", "Brazil", "China, "Mexico", "United States"]
// and target is "Denmark", this funtion will return 3, because "Denmark" goes after China.
function findSpot(list: string[], target: string) {
// A helper function to remove non-alphabetic characters.
const stripNonAlpha = (str: string) => str.replace(/[^a-z]/gi, '');
const strippedTarget = stripNonAlpha(target);
for (let i = 0; i < list.length; i++) {
const strippedItem = stripNonAlpha(list[i]!);
if (strippedTarget.localeCompare(strippedItem) < 0) {
return i;
}
}
return list.length;
}
// Function mergeLists() takes two arrays of strings as parameters, list1 and list2.
// list1 is sorted inascending order and list2 is not sorted.
// Write code so that mergeSort places all elements from list2 into list1 leaving
// list1 sorted. If an element from list2 already exists in list1, it should not
// be added
// For example, if list1 is ["Australia", "Brazil", "China, "Mexico", "United States"]
// and list2 is ["France", "Brasil", "Canada"]
// this function will return
// ["Australia", "Brazil", "Canada", "China, "France", "Mexico", "United States"]
function mergeLists(list1: string[], list2: string[]) {
for (let i = 0; i < list2.length; i++) {
const element = list2[i]
let found = false;
for (let j = 0; j < list1.length; j++) {
if (list1[j] === element) {
found = true;
break;
}
}
if (!found) {
let spot = findSpot(list1, element!);
list1.splice(spot, 0, element!)
}
}
return list1
}
// Complete function displayArray sp that it returns arr string containing all
// the elements from array arr separated by commas.
// For example, if arr is ["Cameroon", "Albania", "Canada", "Barbados", "Zambia"]
// calling displayArray() should return
// Cameroon, Albania, Canada, Barbados, Zambia
function displayArray(arr: string[]){
let s: string = "";
for(let loc=0; loc<arr.length; loc++){
if(loc<arr.length-1)
s = s+ arr[loc] +", "
else
s = s+ arr[loc]
}
return s;
}
///================ TASK ================
// Write code to test your code with the following arrays
// ["Algeria", "Belgium", "Brazil", "Chile", "El Salvador", "Mexico", "Norway", "United States"]
// ["Cameroon", "Albania", "Canada", "Barbados", "Zambia"]
// using the above arrays for list1 and list1 respectively, mergeLists should return
// the following array:
// ["Albania", "Algeria", "Barbados", "Belgium", "Brazil", "Cameroon", "Canada",
// "Chile", "El Salvador", "Mexico", "Norway", "United States", "Zambia"]
let list1: string[] = ["Algeria", "Belgium", "Brazil", "Chile", "El Salvador", "Mexico", "Norway", "United States"]
let list2: string[] = ["Cameroon", "Albania", "Canada", "Barbados", "Zambia"]
console.log("List 1")
console.log(displayArray(list1))
console.log()
console.log("List 2")
console.log(displayArray(list2))
console.log()
console.log("Combined List")
console.log(displayArray(mergeLists(list1, list2)))

8
arrays/Example1.js Normal file
View File

@@ -0,0 +1,8 @@
// creating an array of strings
let animals = ["Zebra", "Koala", "Lion", "Elephan", "Eagle"]
// displaying the items stored in array animals
console.log(animals)
console.log("\narray contains "+ animals.length +" items")

23
arrays/Example2.js Normal file
View File

@@ -0,0 +1,23 @@
// creating an array of strings
let animals = ["Zebra", "Koala", "Lion", "Elephan", "Eagle"]
// displaying the items stored in array animals using a for loop
for(let i=0; i<animals.length; i++)
{
let item = animals[i] // gets item at location i
console.log('Item ' +i +": " +item)
}
console.log()
// displaying the items using the for-in loop
for(let i in animals)
{
let item = animals[i] // gets item at location i
console.log('Item ' +i +": " +item)
}

59
arrays/Example3.js Normal file
View File

@@ -0,0 +1,59 @@
// METHODS OF ARRAYS
/*
push(elem_list): Adds one or more elements to the end of the array,
and returns the new length of the array.
pop(): removes the last element in the array, decrements the length,
and the element that it removed
unshift(elem_list): adds one or more elements to the beginning of the
array and returns the new length of the array
shift(): Removes the first element in the array, decrements the
array length, and returns the element that it removed
join(seperator): when no parameter is passed, this method converts all the elements
of the array to strings and concatenates them seperated
by commas. To change the seperator, you can pass this method
a string literal
toString(): Same as the join method without any parameter passed to it.
*/
// creating an array of strings
console.log("Original Array")
let animals = ["Zebra", "Koala", "Lion", "Elephan", "Eagle"]
console.log(animals)
console.log()
console.log("Inserting Monkey and Snake at end of array")
animals.push("Monkey", "Snake");
console.log(animals)
console.log()
console.log("Removing last element of array")
animals.pop()
console.log(animals)
console.log()
console.log("Inserting Spider and horse at front of array")
animals.unshift("Spider", "horse")
console.log(animals)
console.log()
console.log("Removing first item from array")
animals.shift()
console.log(animals)
console.log()
console.log("Joining array elements in a single string")
let s = animals.join(" ")
console.log(s)
console.log()
// combining array seaanimals and animals into one array named allanimals
console.log("combining array seaanimals and animals into one array named allanimals")
let seaAnimals = ["Shark", "Whale", "Dolphin"]
let allanimals = seaAnimals.concat(animals)
console.log(allanimals)
console.log()

32
arrays/Example4.js Normal file
View File

@@ -0,0 +1,32 @@
// METHODS OF ARRAYS
/*
push(elem_list): Adds one or more elements to the end of the array,
and returns the new length of the array.
*/
let getSum = function(list)
{
let sum=0
for(let i in list)
{
let n = list[i]
sum = sum + n
}
return sum;
}
let getAverage = function(list)
{
let sum = getSum(list);
let ave = sum/list.length
return ave
}
let numbers = [2, 6, 4, 7, 3, 6]
console.log("Array: " +numbers)
let sum = getSum(numbers)
let average = getAverage(numbers)
console.log("Sum = " +sum )
console.log("Average = " +average)

24
arrays/Example5.js Normal file
View File

@@ -0,0 +1,24 @@
// METHODS OF ARRAYS
/*
push(elem_list): Adds one or more elements to the end of the array,
and returns the new length of the array.
*/
let getSum = function(list)
{
let sum=0
for(let i in list)
{
let n = list[i]
sum = sum + n
}
return sum;
}
let numbers = [2, 6, 4, 7, 3, 6]
let min = Math.min.apply(null, numbers)
let max = Math.max.apply(null, numbers)
console.log("Min = " +min)
console.log("Max = " +max)

42
arrays/Example6.js Normal file
View File

@@ -0,0 +1,42 @@
// this function returns the location of the max number stored in array list
let getLocOfMax = function(list)
{
let loc=0
let max = list[0]
for(let i in list)
{
if(max<list[i])
{
max = list[i]
loc = i
}
}
return loc;
}
// this function returns the location of the min number stored in array list
let getLocOfMin = function(list)
{
let loc=0
let min = list[0]
for(let i in list)
{
if(list[i]<min)
{
min = list[i]
loc = i
}
}
return loc;
}
let numbers = [2, 6, 4, 7, 3, 6]
let minLoc = getLocOfMax(numbers)
let maxLoc = getLocOfMin(numbers)
console.log("max Loc: " +minLoc)
console.log("Min Loc: " +maxLoc)

82
arrays/ListOpsExample.js Normal file
View File

@@ -0,0 +1,82 @@
/*
In this list example, I perform the foillowing operations
on a list of numbers:
=> Create the list
=> display the list
=> search for a number in the list using LINEAR Searching
=> Sort the list
*/
// function displayList builds a string named s containing all the items from list list
// and it displays the s
function displayList(list)
{
let s = list[0] +", " +list[1] +", " +list[2] +", " +list[3] +", " +list[4]
+", " +list[5]+", " +list[6] +", " +list[7]+", " +list[8]+", " +list[9]
console.log(s)
}
// Searching algorithm (how to search for a given item in an existing list?)
// The following function named searchItem search for a list n in list numList.
// If n is found the function returns its location in the list, but if n is not
// contained in the list, searchItem return -1
function searchItem(list, n)
{
for(let loc=0; loc<list.length; loc++)
{
if(list[loc]==n)
return loc;
}
return -1
}
// This function sort list numList using the selection algorithm
function sortList(list)
{
for (let i = 0; i<list.length; i++)
{
let loc = i;
for (let j = i + 1; j<list.length; j++)
{
if (list[j] < list[loc])
loc = j;
}
if (loc !== i)
{
let temp = list[i]
list[i] = list[loc]
list[loc] = temp
}
}
}
//The following statement creates a list of 10 integers named numList
let numList = [5, 10, -6, 4, 3, 2, -7, 20, 8, 9]
console.log("Original List")
displayList(numList)
console.log()
let size = numList.length; //gets number of items in numList
console.log("Items in List: "+ size)
console.log()
let number = 20
let loc = searchItem(numList, number) //calls function search list
if(loc>=0)
console.log(number +" is at pos "+ loc)
else
console.log(number +" is not in the list")
console.log()
sortList(numList)
console.log("Sorted List")
displayList(numList)

32
lab/GradeCalculator.js Normal file
View File

@@ -0,0 +1,32 @@
function calcthis() {
let name = document.getElementById("name").value;
let grade = parseInt(document.getElementById("meow").value); // Convert grade to an integer
let resultElement = document.getElementById("result"); // Assuming an element with id "result" to display output
let finalLetterGrade;
if (grade >= 90 && grade <= 100) {
finalLetterGrade = 'A';
} else if (grade >= 80 && grade <= 89) {
finalLetterGrade = 'B';
} else if (grade >= 70 && grade <= 79) {
finalLetterGrade = 'D';
} else if (grade >= 0 && grade <= 69) {
finalLetterGrade = 'F';
// } else if (grade >= 0 && grade <= 9) {
// finalLetterGrade = 'atp jst drop out gng 😭✌️ '
} else {
finalLetterGrade = 'Invalid Grade';
}
if (resultElement) {
if (finalLetterGrade === 'Invalid Grade' || name === '') {
alert("Please check your inputs")
} else {
resultElement.textContent = ` ${name} your letter grade is ${finalLetterGrade}`;
}
} else {
console.error("Element with id 'result' not found to display output.");
}
}

6
lab/GradeCalculator.ts Normal file
View File

@@ -0,0 +1,6 @@
function calcthis() {
let afsdlk = document.getElementById("name").value!;
let dlkafs = document.getElementById("meow").value!;
}
// This script gets input from text boxes

Binary file not shown.

29
lab/index.html Normal file
View File

@@ -0,0 +1,29 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Letter Grade Calcualtor App</title>
<link href="/lab/styles.css" rel="stylesheet" />
<!-- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous"> -->
</head>
<body>
<div class="fgd">
<!-- top header -->
<h1>Letter Grade Calculator</h1>
</div>
<div class="fsd">
<!-- body for the app -->
<h2>Instructions</h2>
<p>Type in your numeric grade and I you will get your correcponding letter grade.</p><br>
<label>Student Name:</label> <input type="text" id="name" placeholder="Bill Gates"/> <br> <br>
<label>Numeric Grade:</label> <input type="number" max="100" id="meow" placeholder="74"/> <br><br>
<button onclick="calcthis()">Get My Letter Grade</button><br><br> <br>
<div class="result">
<p id="result"></p>
</div>
</div>
<!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js" integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI" crossorigin="anonymous"></script> -->
<script src="/lab/GradeCalculator.js"></script>
</body>
</html>

54
lab/styles.css Normal file
View File

@@ -0,0 +1,54 @@
body {
background-color: #205499;
color: rgb(255, 255, 255);
font-family: Arial, Helvetica, sans-serif;
margin: 0;
margin-top: 10px;
}
input {
background-color: rgb(14, 32, 134);
border: none;
padding: 0.2rem;
color: white;
border-radius: 0.2rem;
}
button {
padding: 0.2rem;
border-radius: 0.2rem;
border: none;
}
::-webkit-input-placeholder {
color: rgba(0, 162, 255, 0.808);
}
.fsd {
width: fit-content;
margin: auto;
padding: 20px;
background-color: #1d69ce;
border: 10px solid #154583;
border-radius: 0.5rem;
}
.fgd {
background-color: #1d69ce;
text-align: center;
padding-bottom: 0.005rem;
padding-top: 0.005rem;
margin-bottom: 30px;
font-size: 1.4rem;
}
.result {
background-color: #0f75fa;
padding: 0px 5px;
margin-left: 10px;
margin-right: 10px;
border: 4px solid #154583;
color: rgb(255, 255, 255);
border-radius: 0.5rem;
}
#result{
font-size: 2rem;
margin: 15px 0px;
}

67
meow.ts Normal file
View File

@@ -0,0 +1,67 @@
// humberto mundo
let animals: string[] = ["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: string[], word: string): number {
return list.indexOf(word)
}
// Write a function named getLongest(list) which needs to return the longest string in array
// parameter array
function getLongest(array: string[] ): string {
if (!array) return "provide a array";
let long = array[0]; // init w/ first element
for (let i = 1; i < array.length; i++) {
// const element = list[i];
if (array[i]!.length > long!.length) { // this is why i love and hate typescript :3
long = array[i];
}
}
return long as string;
}
// extra cus y not
function getShortest(list: string[]): string {
if (!list) return "i need array >:("
let short = list[0]
for (let i = 1; i < list.length; i++) {
if (list[i]!.length < short!.length) {
short = list[i]
}
}
return short as string;
}
// 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: string[], word: string): string {
if (!list.includes(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(getShortest(animals)) // Cat
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"

61
mewhenimbored.ts Normal file
View File

@@ -0,0 +1,61 @@
enum CarType {
Sedan = 'Sedan',
SUV = 'SUV',
Hatchback = 'Hatchback',
Truck = 'Truck',
Coupe = 'Coupe',
}
enum RunsOn {
Gasoline = 'Gasoline',
Diesel = 'Diesel',
Hybrid = 'Hybrid',
Electric = 'Electric',
}
// interface ICar {
// make: string;
// model: string;
// year: number;
// body: CarType;
// powertrain: RunsOn;
// engine: string;
// mpg: number;
// link?: string;
// }
class Car {
constructor(
public make: string,
public model: string,
public year: number,
public body: CarType,
public powertrain: RunsOn,
public engine: string,
public mpg: number,
public link?: string
) {}
public info(): string {
// return `${this.year} ${this.make} ${this.model} (${this.body}) - Engine: ${this.engine}, Powertrain: ${this.powertrain}, MPG: ${this.mpg} \nAnd Visit ${this.link} for more infomation`;
let result = `${this.year} ${this.make} ${this.model} (${this.body}) - Engine: ${this.engine}, Powertrain: ${this.powertrain}, MPG: ${this.mpg}`;
if (this.link) {
result += `\nAnd Visit ${this.link} for more information`;
}
return result;
}
}
const myCar = new Car(
'Honda', // Make
'Civic', // Model
2025, // Year
CarType.Hatchback, // Body
RunsOn.Gasoline, // PowerTrain
'2L 4-Cylinder', // Engine
49,
"https://automobiles.honda.com/2024/civic-sedan/specs-features-trim-comparison"
);
console.log(myCar.info());

63
mrmundo.js Normal file
View 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');

52
package-lock.json generated Normal file
View File

@@ -0,0 +1,52 @@
{
"name": "AP Computer Science Principles",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"tsc": "^2.0.4"
},
"devDependencies": {
"@types/node": "^24.5.1",
"typescript": "^5.9.2"
}
},
"node_modules/@types/node": {
"version": "24.5.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.5.1.tgz",
"integrity": "sha512-/SQdmUP2xa+1rdx7VwB9yPq8PaKej8TD5cQ+XfKDPWWC+VDJU4rvVVagXqKUzhKjtFoNA8rXDJAkCxQPAe00+Q==",
"dev": true,
"dependencies": {
"undici-types": "~7.12.0"
}
},
"node_modules/tsc": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/tsc/-/tsc-2.0.4.tgz",
"integrity": "sha512-fzoSieZI5KKJVBYGvwbVZs/J5za84f2lSTLPYf6AGiIf43tZ3GNrI1QzTLcjtyDDP4aLxd46RTZq1nQxe7+k5Q==",
"bin": {
"tsc": "bin/tsc"
}
},
"node_modules/typescript": {
"version": "5.9.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.2.tgz",
"integrity": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=14.17"
}
},
"node_modules/undici-types": {
"version": "7.12.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.12.0.tgz",
"integrity": "sha512-goOacqME2GYyOZZfb5Lgtu+1IDmAlAEu5xnD3+xTzS10hT0vzpf0SPjkXwAw9Jm+4n/mQGDP3LO8CPbYROeBfQ==",
"dev": true
}
}
}

9
package.json Normal file
View File

@@ -0,0 +1,9 @@
{
"devDependencies": {
"@types/node": "^24.5.1",
"typescript": "^5.9.2"
},
"dependencies": {
"tsc": "^2.0.4"
}
}

53
problem1.js Normal file
View File

@@ -0,0 +1,53 @@
// Function computeAverage() is complete. This function
// takes an array of test named scores and two integers, from and to.
// computeScores returns the average of all the scores starting at
// from and ending at to, inclusive
function computeScores(scores, from, to)
{
//DO NOT WRITE ANY CODE HERE
let sum = 0;
let average =0;
for(let i=from; i<=to; i++)
{
sum = sum + scores[i]
}
average = sum/(to-from+1)
return average
}
// Function getRange() is complete. This function
// takes an array of test scores and two integers, from and to.
// getRange returns a string consisting of all the scores from scores
// starting at from and ending at to, inclusive separated by a space
function getRange(scores, from, to)
{
//DO NOT WRITE ANY CODE HERE
let s="";
for(let i=from; i<=to; i++)
{
s = s + scores[i] +" "
}
return s
}
// ======= Your task is specified in the WORD DOCUMENT ================
let scores = [95, 100,80, 80, 100, 80, 60, 80, 90]
let scores2 = [95, 60, 80, 80, 50, 80, 60, 80, 90]
let scores3 = [95, 100, 75, 80, 80, 80, 60, 80, 75]
console.log(`Scores: ${getRange(scores, 2, 5)}`)
console.log(`Average:${computeScores(scores, 2, 5)}`)
console.log()
console.log(`Scores: ${getRange(scores2, 4, 8)}`)
console.log(`Average:${computeScores(scores2, 4, 8)}`)
console.log()
console.log(`Scores: ${getRange(scores3, 0, 8)}`)
console.log(`Average:${computeScores(scores3, 0, 8)}`)

46
problem1.ts Normal file
View File

@@ -0,0 +1,46 @@
// Function computeAverage() is complete. This function
// takes an array of test named scores and two integers, from and to.
// computeScores returns the average of all the scores starting at
// from and ending at to, inclusive
function computeScores(scores:number[], from: number, to:number): number {
//DO NOT WRITE ANY CODE HERE
let sum = 0;
let average =0;
for(let i=from; i<=to; i++)
{
sum = sum + scores[i]!
}
average = sum/(to-from+1)
return average
}
// Function getRange() is complete. This function
// takes an array of test scores and two integers, from and to.
// getRange returns a string consisting of all the scores from scores
// starting at from and ending at to, inclusive separated by a space
function getRange(scores: number[], from: number, to:number): string {
//DO NOT WRITE ANY CODE HERE
let s="";
for(let i=from; i<=to; i++)
{
s = s + scores[i] +" "
}
return s
}
// ======= Your task is specified in the WORD DOCUMENT ================
console.log(`Scores: ${getRange([95, 100,80, 80, 100, 80, 60, 80, 90], 2, 5)}`)
console.log(`Average:${computeScores([95, 100,80, 80, 100, 80, 60, 80, 90], 2, 5)}`)
console.log()
console.log(`Scores: ${getRange( [95, 60, 80, 80, 50, 80, 60, 80, 90], 4, 8)}`)
console.log(`Average:${computeScores( [95, 60, 80, 80, 50, 80, 60, 80, 90], 4, 8)}`)
console.log()
console.log(`Scores: ${getRange([95, 100, 75, 80, 80, 80, 60, 80, 75], 0, 8)}`)
console.log(`Average:${computeScores([95, 100, 75, 80, 80, 80, 60, 80, 75], 0, 8)}`)

101
problem2.js Normal file
View File

@@ -0,0 +1,101 @@
//Function displayList is complete
//Function displayList returns a string (a list of) of all test scores
//stored in the parameter array named scores
function displayList(scores)
{
let s = ""
for(let loc=0; loc<scores.length; loc++)
{
if(loc<scores.length-1)
s = s+ scores[loc] +", "
else
s = s+ scores[loc]
}
return s;
}
// function hasImproved() takes as parameter an array of scores named scores.
// This function returns TRUE if all scores are improving, returns FALSE otherwise.
// scores are said to be improving if all scores in the list are greater than the
// previous score. For example [50, 80, 90, 100] is improving since any given score
// in the list is greater than the previous. On the otherhand, scores [90, 95, 85, 100]
// are not improving because 85<95
function hasImproved(scores)
{
//DO NOT WRITE ANY CODE HERE
for(let i=0; i<scores.length-1; i++)//5 6 8 9 4
{
for(let j=i+1; j<scores.length-2; j++)
{
if(scores[j]<scores[i])
return false
}
}
return true
}
// function getAverage is complete.
// This function takes an array of test scores and two integers, start and end.
// getAverage returns the average of all scores starting at start and end
// at to inclusive. For example. if scores is [80, 85, 75, 90, 100, 50] and
// start=2 and end=4, getAverage will return the average of 75, 90 and 100
function getAverage(scores, start, end)
{
//DO NOT WRITE ANY CODE HERE
let sum=0;
for(let i=start; i<=end; i++)
{
sum = sum + scores[i]
}
return sum/(end-start+1)
}
// ******************************** TASK 1 ***********************************
// Function computeGrade() takes as parameters an array of student test scores
// named scores.
// This function needs to return the average of this student. The average
// needs to be computed according to the following rules:
// 1. If the student has improve, the average is computed from the scores on the
// second half of the list ONLY. If the list has odd number of scores, the extra score
// is part of the second half. For example, if the student test scores list is
// [50, 80, 85, 90, 95] the average should be calculated with scores [85, 90, 95] use LabArrays for this, and use improve function for boolean :3
// 2. If the student has not improved, the average score is calculated including
// all the test scores
function computeGrade(scores)
{
if (hasImproved(scores)) {
let temparray = scores.slice(Math.ceil(scores.length / 2), scores.length)
return getAverage(temparray, 0, temparray.length-1)
} else {
// console.log("nuh uh")
return getAverage(scores, 0, scores.length-1);
}
}
// ******************************** TASK 2 ***********************************
// Write the code to calculate the average of the following test scores and
// display the data as shown in the sample run of the program shown in the
// WORD DOCUMENT.
// [95, 100, 80, 80, 100, 80, 60, 80, 90]
// [95, 60, 80, 80, 50, 80, 60, 80, 90]
// [95, 100, 75, 80, 80, 80, 60, 80, 75]
// You MUST use the other given functions when completing this TASK
let array = [85, 90, 96, 97, 98, 100]
let array2 = [95, 60, 100, 80, 80, 85, 87, 90]
let array3 = [95, 100, 75, 80, 80, 80, 60, 80, 75]
console.log(`Test Scores: ${displayList(array)}`)
console.log(`Average = ${computeGrade(array)}`)
console.log()
console.log(`Test Scores: ${displayList(array2)}`)
console.log(`Average = ${computeGrade(array2)}`)
console.log()
console.log(`Test Scores: ${displayList(array3)}`)
console.log(`Average = ${computeGrade(array3)}`)

97
problem2.ts Normal file
View File

@@ -0,0 +1,97 @@
//Function displayList is complete
//Function displayList returns a string (a list of) of all test scores
//stored in the parameter array named scores
function displayList(scores: number[]): string
{
let s = ""
for(let loc=0; loc<scores.length; loc++)
{
if(loc<scores.length-1)
s = s+ scores[loc] +", "
else
s = s+ scores[loc]
}
return s;
}
// function hasImproved() takes as parameter an array of scores named scores.
// This function returns TRUE if all scores are improving, returns FALSE otherwise.
// scores are said to be improving if all scores in the list are greater than the
// previous score. For example [50, 80, 90, 100] is improving since any given score
// in the list is greater than the previous. On the otherhand, scores [90, 95, 85, 100]
// are not improving because 85<95
function hasImproved(scores: number[]): boolean
{
//DO NOT WRITE ANY CODE HERE
for(let i=0; i<scores.length-1; i++)//5 6 8 9 4
{
for(let j=i+1; j<scores.length-2; j++)
{
if(scores[j]!<scores[i]!)
return false
}
}
return true
}
// function getAverage is complete.
// This function takes an array of test scores and two integers, start and end.
// getAverage returns the average of all scores starting at start and end
// at to inclusive. For example. if scores is [80, 85, 75, 90, 100, 50] and
// start=2 and end=4, getAverage will return the average of 75, 90 and 100
function getAverage(scores: number[], start:number, end: number): number
{
//DO NOT WRITE ANY CODE HERE
let sum=0;
for(let i=start; i<=end; i++)
{
sum = sum + scores[i]!
}
return sum/(end-start+1)
}
// ******************************** TASK 1 ***********************************
// Function computeGrade() takes as parameters an array of student test scores
// named scores.
// This function needs to return the average of this student. The average
// needs to be computed according to the following rules:
// 1. If the student has improve, the average is computed from the scores on the
// second half of the list ONLY. If the list has odd number of scores, the extra score
// is part of the second half. For example, if the student test scores list is
// [50, 80, 85, 90, 95] the average should be calculated with scores [85, 90, 95] use LabArrays for this, and use improve function for boolean :3
// 2. If the student has not improved, the average score is calculated including
// all the test scores
function computeGrade(scores: number[])
{
if (hasImproved(scores)) {
let temparray: number[] = scores.slice(Math.ceil(scores.length / 2), scores.length)
return getAverage(temparray, 0, temparray.length-1)
} else {
return getAverage(scores, 0, scores.length-1);
}
}
// ******************************** TASK 2 ***********************************
// Write the code to calculate the average of the following test scores and
// display the data as shown in the sample run of the program shown in the
// WORD DOCUMENT.
// [95, 100, 80, 80, 100, 80, 60, 80, 90]
// [95, 60, 80, 80, 50, 80, 60, 80, 90]
// [95, 100, 75, 80, 80, 80, 60, 80, 75]
// You MUST use the other given functions when completing this TASK
let array: number[] = [85, 90, 96, 97, 98, 100]
let array2: number[] = [95, 60, 100, 80, 80, 85, 87, 90]
let array3: number[] = [95, 100, 75, 80, 80, 80, 60, 80, 75]
console.log(`Test Scores: ${displayList(array)}`)
console.log(`Average = ${computeGrade(array)}`)
console.log()
console.log(`Test Scores: ${displayList(array2)}`)
console.log(`Average = ${computeGrade(array2)}`)
console.log()
console.log(`Test Scores: ${displayList(array3)}`)
console.log(`Average = ${computeGrade(array3)}`)

20
sort.js Normal file
View File

@@ -0,0 +1,20 @@
let sort = [5, 10, -6, 4, 3, 2, -7, 20, 8, 9]
function sortList(list) {
for(let i=0; i< list.length-1; i++) {
let pos = i // o
for (let j=i+0; i<list.length-1; j++) {
if (list[j]<list[pos]) {
pos = j
}
if (pos !== i) {
let temp = list[i];
list[i] = list[j];
list[j] = temp; // Corrected line
}
}
}
}
console.log(sortList(sort))

24
sort.ts Normal file
View File

@@ -0,0 +1,24 @@
let sort = [5, 10, -6, 4, 3, 2, -7, 20, 8, 9]
function sortList(list: number[]) {
for(let i=0; i< list.length-1; i++) {
let pos = i // o
for (let j=i+0; i<list.length-1; j++) {
if (list[j]<list[pos]) {
pos = j
}
if (pos !== i) {
let temp = list[i];
list[i] = list[j];
list[j] = temp; // Corrected line
}
}
return pos
}
}
console.log(sortList(sort))
sort.toLocaleString

44
tsconfig.json Normal file
View File

@@ -0,0 +1,44 @@
{
// Visit https://aka.ms/tsconfig to read more about this file
"compilerOptions": {
// File Layout
// "rootDir": "./src",
// "outDir": "./dist",
// Environment Settings
// See also https://aka.ms/tsconfig/module
"module": "nodenext",
"target": "esnext",
"types": [],
// For nodejs:
"lib": ["ES2018", "dom"],
// "types": ["node"],
// and npm install -D @types/node
// Other Outputs
"sourceMap": true,
"declaration": true,
"declarationMap": true,
// Stricter Typechecking Options
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
// Style Options
// "noImplicitReturns": true,
// "noImplicitOverride": true,
// "noUnusedLocals": true,
// "noUnusedParameters": true,
// "noFallthroughCasesInSwitch": true,
// "noPropertyAccessFromIndexSignature": true,
// Recommended Options
"strict": true,
"jsx": "react-jsx",
"verbatimModuleSyntax": true,
"isolatedModules": true,
"noUncheckedSideEffectImports": true,
"moduleDetection": "force",
"skipLibCheck": true,
}
}

50
typescriptisbetter.js Normal file
View File

@@ -0,0 +1,50 @@
// humberto mundo
var 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";
var long = array[0]; // init w/ first element
for (var i = 1; i < array.length; i++) {
// const element = list[i];
if (array[i].length > long.length) { // this is why i love and hate typescript :3
long = array[i];
}
}
return long;
}
// extra cus y not
function getShortest(list) {
if (!list)
return "i need array >:(";
var short = list[0];
for (var i = 1; i < list.length; i++) {
if (list[i].length < short.length) {
short = list[i];
}
}
return short;
}
// 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 (!list.includes(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(getShortest(animals)); // Cat
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"

67
typescriptisbetter.ts Normal file
View File

@@ -0,0 +1,67 @@
// humberto mundo
let animals: string[] = ["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: string[], word: string): number {
return list.indexOf(word)
}
// Write a function named getLongest(list) which needs to return the longest string in array
// parameter array
function getLongest(array: string[] ): string {
if (!array) return "provide a array";
let long = array[0]; // init w/ first element
for (let i = 1; i < array.length; i++) {
// const element = list[i];
if (array[i]!.length > long!.length) { // this is why i love and hate typescript :3
long = array[i];
}
}
return long as string;
}
// extra cus y not
function getShortest(list: string[]): string {
if (!list) return "i need array >:("
let short = list[0]
for (let i = 1; i < list.length; i++) {
if (list[i]!.length < short!.length) {
short = list[i]
}
}
return short as string;
}
// 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: string[], word: string): string {
if (!list.includes(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(getShortest(animals)) // Cat
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"