
Within the first two weeks of class for ICS 314, we were introduced to a coding language that I am somewhat familiar with, without even knowing it: TypeScript. I say this because I have some experience working with JavaScript when I was in high-school but haven’t used it in a while. With a mix of homework assignments and practice WODs (workout of the day), I found the experience to be both exciting and stressful.
From what I have learned so far, TypeScript seems to be a much more flexible compared to the languages I am used to, such as Java and C. An example of this would be variables. TypeScript has Tuples which is a fixed array with different types of variables. You can also return various types of variables when writing a function which is something that I have never worked with before since Java and C don’t offer this feature. Similar to this, union types were also interesting to me because Java requires explicit type declarations and prevents variables from changing types once it has been declared and C does the same but can be changed with the use of casting.
The learning process has been a little bit of a roller coaster for me. Like learning any other coding language, it takes some time to get used to the different syntax and unique features that it offers. Since I have mainly work with Java and C, I sometimes type the wrong syntax due to muscle memory. A basic example would be printing out a statement. C uses printf() while TypeScript uses console.log(). Creating functions was also something that I had to get used to since the return type is after the parameters and there could be multiple return types which is something I have never worked with before. This can get a little frustrating because of the learning curve of constantly having to look for references on Google if I forget either a syntax or method. However, the satisfaction of completing even the most basic problems and learning new ways of solving a problem is what keeps this learning experience fun for me.
WODs are short assignments that have set times for when you should be able to complete the given problem. I find the practice WODs to be very useful as it allows me to test whether or not I remember the syntax while also being able to see what I have to review. This type of assignment is something that I quite enjoy since it brings out a competitive side of me due to wanting to beat my previous time and to see if I can figure out multiple solutions. The timer however can be quite intimidating at first but it forces me to ensure maximum efficiency and prepares me for future challenges that have time limits like job interviews.
My First WOD
Task
- Find the sum of all the multiples of 3 or 5 below 1000. Create a Typescript function called “projectEulerOne”.
Fastest Time
- 3 minutes amd 33 seconds.
Code:
function projectEulerOne (num: number):number{
let sum: number = 0;
for(let i = 1; i < num; i++){
if(i % 3 === 0){
sum+=i;
}else if(i % 5 === 0){
sum+=i;
}
}
return sum;
}
console.log(projectEulerOne(1000));
Overall, I find learning TypeScript to be quite entertaining so far due to the mix of learning its new features and the way it is being taught. I hope that after these next few weeks or months, I will be able to get comfortable with TypeScript to the point where I can possibly start my own project using it.