21. Write a TypeScript program to sort an array of numbers in ascending order.

Required Input:

[5, 2, 9, 1, 5, 6]

Expected Output:

Sorted Array: [1,2,5,5,6,9]

Code In Typescript

let numbers: number[]; function sortArray(arr: number[]): number[] { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

22. Create an enum for the days of the week and print a specific day.

Required Input:

Day: Wednesday

Expected Output:

Today is Wednesday

Code In Typescript

enum DaysOfWeek { // Define enum values } let today: DaysOfWeek; // Your logic here

Run Code?

Click Run Button to view compiled output

23. Write a program to calculate the sum of all even numbers in an array.

Required Input:

[1, 2, 3, 4, 5, 6]

Expected Output:

Sum of even numbers: 12

Code In Typescript

let numbers: number[]; function sumEvenNumbers(arr: number[]): number { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

24. Write a TypeScript function to count the number of vowels in a string.

Required Input:

"hello world"

Expected Output:

Number of vowels: 3

Code In Typescript

function countVowels(str: string): number { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

25. Create a class Car with properties brand and year. Create an object and print its details.

Required Input:

Brand: "Toyota", Year: 2020

Expected Output:

Brand: Toyota, Year: 2020

Code In Typescript

class Car { // Define properties and constructor } let myCar = new Car("Toyota", 2020); console.log(Brand: ${myCar.brand}, Year: ${myCar.year});

Run Code?

Click Run Button to view compiled output

26. Write a program to check if an array contains a specific value.

Required Input:

Array: [10, 20, 30, 40, 50], Value: 30

Expected Output:

30 is present in the array

Code In Typescript

let numbers: number[]; let value: number; function containsValue(arr: number[], val: number): boolean { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

27. Create a function that takes an object and prints all its keys and values.

Required Input:

Object: { name: "Alice", age: 25, city: "New York" }

Expected Output:

name: Alice
age: 25
city: New York

Code In Typescript

let person: { [key: string]: string

Run Code?

Click Run Button to view compiled output

28. Write a function to capitalize the first letter of each word in a sentence.

Required Input:

"hello world"

Expected Output:

Hello World

Code In Typescript

function capitalizeWords(sentence: string): string { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

29. Write a TypeScript program to merge two arrays and remove duplicate values.

Required Input:

Array 1: [1, 2, 3], Array 2: [2, 3, 4, 5]

Expected Output:

Merged Array: [ 1, 2, 3, 4, 5 ]

Code In Typescript

let array1: number[]; let array2: number[]; function mergeAndRemoveDuplicates(arr1: number[], arr2: number[]): number[] { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

30. Write a program to find the index of a specific value in an array.

Required Input:

Array: [5, 10, 15, 20], Value: 15

Expected Output:

Index of 15: 2

Code In Typescript

let numbers: number[]; let value: number; function findIndex(arr: number[], val: number): number { // Your logic here } // Call the function

Run Code?

Click Run Button to view compiled output

ad vertical

3 of 3