Skip to content

Hello Developers, I have embarked on my journey of next-level learning. All of my learning activities and notes will be available here. If you are interested in exploring and learning new things, you can check it out. I will be sharing modules learned throughout this journey on this link. So, go ahead and take a look. Happy learning!

Notifications You must be signed in to change notification settings

shahidmonowarr/typescript-technocrat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

typescript-technocrat

Simple TypeScript Practice Problems:


  1. Convert the following JavaScript array into a TypeScript tuple
    const userInfo = [101, "Ema", "John", true,  , "2023"];
  1. Write a TypeScript function that takes in two arrays of numbers as parameters. The function should compare the elements in both arrays and return a new array that contains only the elements that are present in both arrays.

    For example, if the first array is [1, 2, 3, 4, 5] and the second array is [2, 4, 6, 8], the function should return a new array with the elements 2 and 4 because they are present in both arrays.

    The function should handle arrays of any length and should return the resulting array in the same order as they appear in the first array.

  2. You have an interface for Product, containing the product's id, name, price, and category. You want to filter an array of Products based on a specific criterion and value.

    Write a TypeScript generic function that takes this array, a criterion , and returns a new array containing only the products that match the given criterion and value. Use a generic type parameter in the function signature to ensure type safety.

  3. Suppose you have an array of tuples, where each tuple represents a product and contains the product name, price, and quantity. Write a TypeScript function that calculates the total cost of all the products in the array, using a generic type for the tuple and a type alias for the array.

  4. Suppose you have an array of numbers in TypeScript, and you want to find the sum of all the even numbers in the array. How would you approach this problem and write code to solve it?

  5. Create an interface called Person that includes properties for name (string), age (number), and email (string). Then create an array of Person objects and write a function that takes the array and a string email as parameters, and returns the Person object that matches the email or null if no match is found.

  6. Create a TypeScript program that declares an array of numbers. Use the spread  operator to pass the elements of the array as arguments to a function that finds the minimum and maximum values of the array. Use destructuring to assign the minimum and maximum values to separate variables, and log them to the console.

  7. Create a TypeScript program that declares a function that takes a string parameter with a literal type of "red", "green", or "blue", and an optional boolean parameter. If the boolean parameter is true, log the string parameter in uppercase. If the boolean parameter is false or not provided, log the string parameter in lowercase.

About

Hello Developers, I have embarked on my journey of next-level learning. All of my learning activities and notes will be available here. If you are interested in exploring and learning new things, you can check it out. I will be sharing modules learned throughout this journey on this link. So, go ahead and take a look. Happy learning!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published