Upload files to "/"

This commit is contained in:
2025-10-27 11:50:03 -05:00
parent bccb3378c6
commit a383913b42
5 changed files with 286 additions and 0 deletions

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)}`)