Skip to content

Instantly share code, notes, and snippets.

View dontpaniclabsgists's full-sized avatar

Don't Panic Labs dontpaniclabsgists

View GitHub Profile
let numbers: number[] = [85, 90, 78, 92, 88];
let total = 0;
for (let index in numbers) {
total += numbers[index];
}
let average = total / numbers.length;
console.log("Average:", average); // Output: 86.6
let numbers: number[] = [85, 90, 78, 92, 88];
let total = 0;
for (let number of numbers) {
total += number;
}
let average = total / numbers.length;
console.log("Average:", average); // Output: 86.6
let numbers: number[] = [85, 90, 78, 92, 88];
let total = 0;
let count = numbers.length;
numbers.forEach((number) => {
total += number;
});
let average = total / count;
console.log("Average:", average); //Output is 86.6
let numbers: number[] = [85, 90, 78, 92, 88];
let total = 0;
let count = numbers.length;
for (let i = 0; i < count; i++) {
total += numbers[i];
}
let average = total / count;
console.log("Average:", average); //Output is 86.6
let numbers: number[] = [85, 90, 78, 92, 88];
let total = 0;
let count = numbers.length;
let i = 0;
do {
total += numbers[i];
i++;
} while (i < count);
let numbers: number[] = [85, 90, 78, 92, 88];
let total = 0;
let count = numbers.length;
let i = 0;
while (i < count) {
total += numbers[i];
i++;
}
let scores: numbers[] = [55, 82, 21];
let sports: string[] = ['Volleyball', 'Football', 'Basketball', 'Soccer'];
sports[1] = 'Tennis';
// Replaces 'Football' with 'Tennis'
console.log(sports);
// Output: ['Volleyball', 'Tennis', 'Basketball', 'Soccer']
let sports: string[] = ['Volleyball', 'Football', 'Basketball', 'Soccer'];
let notification: NotificationSender;
notification = new EmailSender("Project Update", "[email protected]");
notification.send(); // Output: Sending email: 'Project Update' to [email protected]
notification = new SMSSender("Meeting at 3 PM", "123456789");
notification.send(); // Output: Sending SMS: 'Meeting at 3 PM' to 123456789