Workshop Typescript exercise on data types and functions.
The main purpose of this exercise is to get familiar with Typescsript's data types and function declarations.
For this exercise you need to have NodeJs
and also Typescript installed
$ npm i -g typescript
Given a language that uses only 4 letters
{ A, T, G, C}
and a grammar of the following 2 rules
A can only pair with T, and vice versa
G can only pair with C, and vice versa
so it is:
A -> T
T -> A
G -> C
C -> G
Create a function that takes any sequence of those 4 letters and replies with a sequence of the complementary letters i.e the letters they pair with.
So if sequence is
ATGCATCAGACT
Then the solution should be
TACGTAGTCTGA
Try and be more strict when declaring a variable
const myVar = 'anything'; // Bad!
const myVar: string = 'anything'; // Good!
and also when declaring a function
const add = (x, y) => x + y; // Bad!
const add = (x: number, y: number): number => x + y; // Good!
If you need to convert an enum to string
enum Base { A, T, G, C}
const name: string = Base[Base.A];
If you like, we have provided a file containing a sequence
collagen.ts
You may import it like this
import {collagen} from './collagen';
To compile and run your code
$ tsc your_file.ts && node your_file.js