RNA transcription
This commit is contained in:
13
typescript/rna-transcription/.eslintignore
Normal file
13
typescript/rna-transcription/.eslintignore
Normal file
@@ -0,0 +1,13 @@
|
||||
!.meta
|
||||
|
||||
# Protected or generated
|
||||
.git
|
||||
.vscode
|
||||
|
||||
# When using npm
|
||||
node_modules/*
|
||||
|
||||
# Configuration files
|
||||
.eslintrc.cjs
|
||||
babel.config.cjs
|
||||
jest.config.cjs
|
||||
38
typescript/rna-transcription/.eslintrc.cjs
Normal file
38
typescript/rna-transcription/.eslintrc.cjs
Normal file
@@ -0,0 +1,38 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
parserOptions: {
|
||||
tsconfigRootDir: __dirname,
|
||||
project: ['./tsconfig.json'],
|
||||
},
|
||||
overrides: [
|
||||
// Student provided files
|
||||
{
|
||||
files: ['*.ts'],
|
||||
excludedFiles: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
|
||||
extends: '@exercism/eslint-config-typescript',
|
||||
},
|
||||
// Exercism given tests
|
||||
{
|
||||
files: ['*.test.ts'],
|
||||
excludedFiles: ['custom.test.ts'],
|
||||
env: {
|
||||
jest: true,
|
||||
},
|
||||
extends: '@exercism/eslint-config-typescript/maintainers',
|
||||
},
|
||||
// Student provided tests
|
||||
{
|
||||
files: ['custom.test.ts'],
|
||||
env: {
|
||||
jest: true,
|
||||
},
|
||||
extends: '@exercism/eslint-config-typescript',
|
||||
},
|
||||
// Exercism provided files
|
||||
{
|
||||
files: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
|
||||
excludedFiles: ['custom.test.ts'],
|
||||
extends: '@exercism/eslint-config-typescript/maintainers',
|
||||
},
|
||||
],
|
||||
}
|
||||
12
typescript/rna-transcription/.exercism/config.json
Normal file
12
typescript/rna-transcription/.exercism/config.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"blurb": "Given a DNA strand, return its RNA Complement Transcription.",
|
||||
"authors": ["masters3d"],
|
||||
"contributors": ["DFXLuna", "lukaszklis", "SleeplessByte"],
|
||||
"files": {
|
||||
"solution": ["rna-transcription.ts"],
|
||||
"test": ["rna-transcription.test.ts"],
|
||||
"example": [".meta/proof.ci.ts"]
|
||||
},
|
||||
"source": "Hyperphysics",
|
||||
"source_url": "http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html"
|
||||
}
|
||||
1
typescript/rna-transcription/.exercism/metadata.json
Normal file
1
typescript/rna-transcription/.exercism/metadata.json
Normal file
@@ -0,0 +1 @@
|
||||
{"track":"typescript","exercise":"rna-transcription","id":"eee7b8a71a5343a7888cbc9dfff01b07","url":"https://exercism.org/tracks/typescript/exercises/rna-transcription","handle":"briemens","is_requester":true,"auto_approve":false}
|
||||
44
typescript/rna-transcription/HELP.md
Normal file
44
typescript/rna-transcription/HELP.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Help
|
||||
|
||||
## Running the tests
|
||||
|
||||
Execute the tests with:
|
||||
|
||||
```bash
|
||||
$ yarn test
|
||||
```
|
||||
|
||||
## Skipped tests
|
||||
|
||||
In the test suites all tests but the first have been skipped.
|
||||
|
||||
Once you get a test passing, you can enable the next one by changing `xit` to
|
||||
`it`.
|
||||
|
||||
## Submitting your solution
|
||||
|
||||
You can submit your solution using the `exercism submit rna-transcription.ts` command.
|
||||
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||
|
||||
It's possible to submit an incomplete solution which allows you to:
|
||||
|
||||
- See how others have completed the exercise
|
||||
- Request help from a mentor
|
||||
|
||||
## Need to get help?
|
||||
|
||||
If you'd like help solving the exercise, check the following pages:
|
||||
|
||||
- The [TypeScript track's documentation](https://exercism.org/docs/tracks/typescript)
|
||||
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||
|
||||
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||
|
||||
To get help if you're having trouble, you can use one of the following resources:
|
||||
|
||||
- [TypeScript QuickStart](https://www.typescriptlang.org/docs/handbook/release-notes/overview.html)
|
||||
- [ECMAScript 2015 Language Specification](https://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2015.pdf) (pdf)
|
||||
- [Mozilla JavaScript Reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference)
|
||||
- [/r/typescript](https://www.reddit.com/r/typescript) is the TypeScript subreddit.
|
||||
- [StackOverflow](https://stackoverflow.com/questions/tagged/typescript) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
|
||||
40
typescript/rna-transcription/README.md
Normal file
40
typescript/rna-transcription/README.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# RNA Transcription
|
||||
|
||||
Welcome to RNA Transcription on Exercism's TypeScript Track.
|
||||
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||
|
||||
## Instructions
|
||||
|
||||
Given a DNA strand, return its RNA complement (per RNA transcription).
|
||||
|
||||
Both DNA and RNA strands are a sequence of nucleotides.
|
||||
|
||||
The four nucleotides found in DNA are adenine (**A**), cytosine (**C**),
|
||||
guanine (**G**) and thymine (**T**).
|
||||
|
||||
The four nucleotides found in RNA are adenine (**A**), cytosine (**C**),
|
||||
guanine (**G**) and uracil (**U**).
|
||||
|
||||
Given a DNA strand, its transcribed RNA strand is formed by replacing
|
||||
each nucleotide with its complement:
|
||||
|
||||
- `G` -> `C`
|
||||
- `C` -> `G`
|
||||
- `T` -> `A`
|
||||
- `A` -> `U`
|
||||
|
||||
## Source
|
||||
|
||||
### Created by
|
||||
|
||||
- @masters3d
|
||||
|
||||
### Contributed to by
|
||||
|
||||
- @DFXLuna
|
||||
- @lukaszklis
|
||||
- @SleeplessByte
|
||||
|
||||
### Based on
|
||||
|
||||
Hyperphysics - http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html
|
||||
4
typescript/rna-transcription/babel.config.cjs
Normal file
4
typescript/rna-transcription/babel.config.cjs
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
presets: ['@exercism/babel-preset-typescript'],
|
||||
plugins: [],
|
||||
}
|
||||
19
typescript/rna-transcription/jest.config.cjs
Normal file
19
typescript/rna-transcription/jest.config.cjs
Normal file
@@ -0,0 +1,19 @@
|
||||
module.exports = {
|
||||
verbose: true,
|
||||
projects: ['<rootDir>'],
|
||||
testMatch: [
|
||||
'**/__tests__/**/*.[jt]s?(x)',
|
||||
'**/test/**/*.[jt]s?(x)',
|
||||
'**/?(*.)+(spec|test).[jt]s?(x)',
|
||||
],
|
||||
testPathIgnorePatterns: [
|
||||
'/(?:production_)?node_modules/',
|
||||
'.d.ts$',
|
||||
'<rootDir>/test/fixtures',
|
||||
'<rootDir>/test/helpers',
|
||||
'__mocks__',
|
||||
],
|
||||
transform: {
|
||||
'^.+\\.[jt]sx?$': 'babel-jest',
|
||||
},
|
||||
}
|
||||
15996
typescript/rna-transcription/package-lock.json
generated
Normal file
15996
typescript/rna-transcription/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
31
typescript/rna-transcription/package.json
Normal file
31
typescript/rna-transcription/package.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "@exercism/typescript-rna-transcription",
|
||||
"version": "1.0.0",
|
||||
"description": "Exercism exercises in Typescript.",
|
||||
"private": true,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/exercism/typescript"
|
||||
},
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": "^14.13.1 || >=16.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@exercism/babel-preset-typescript": "^0.1.0",
|
||||
"@exercism/eslint-config-typescript": "^0.4.1",
|
||||
"@types/jest": "^27.4.0",
|
||||
"@types/node": "^16.11.24",
|
||||
"babel-jest": "^27.5.1",
|
||||
"core-js": "^3.21.0",
|
||||
"eslint": "^8.9.0",
|
||||
"jest": "^27.5.1",
|
||||
"typescript": "^4.5.4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "yarn lint:types && jest --no-cache",
|
||||
"lint": "yarn lint:types && yarn lint:ci",
|
||||
"lint:types": "yarn tsc --noEmit -p .",
|
||||
"lint:ci": "eslint . --ext .tsx,.ts"
|
||||
}
|
||||
}
|
||||
35
typescript/rna-transcription/rna-transcription.test.ts
Normal file
35
typescript/rna-transcription/rna-transcription.test.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { toRna } from "./rna-transcription";
|
||||
|
||||
describe("Transcriptor", () => {
|
||||
it("transcribes cytosine to guanine", () => {
|
||||
expect(toRna("C")).toEqual("G");
|
||||
});
|
||||
|
||||
it("transcribes guanine to cytosine", () => {
|
||||
expect(toRna("G")).toEqual("C");
|
||||
});
|
||||
|
||||
it("transcribes adenine to uracil", () => {
|
||||
expect(toRna("A")).toEqual("U");
|
||||
});
|
||||
|
||||
it("transcribes thymine to adenine", () => {
|
||||
expect(toRna("T")).toEqual("A");
|
||||
});
|
||||
|
||||
it("transcribes all dna nucleotides to their rna complements", () => {
|
||||
expect(toRna("ACGTGGTCTTAA")).toEqual("UGCACCAGAAUU");
|
||||
});
|
||||
|
||||
it("correctly handles invalid input", () => {
|
||||
expect(() => toRna("U")).toThrowError("Invalid input DNA.");
|
||||
});
|
||||
|
||||
it("correctly handles completely invalid input", () => {
|
||||
expect(() => toRna("XXX")).toThrowError("Invalid input DNA.");
|
||||
});
|
||||
|
||||
it("correctly handles partially invalid input", () => {
|
||||
expect(() => toRna("ACGTXXXCTTAA")).toThrowError("Invalid input DNA.");
|
||||
});
|
||||
});
|
||||
24
typescript/rna-transcription/rna-transcription.ts
Normal file
24
typescript/rna-transcription/rna-transcription.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
const COMPLEMENTS = {
|
||||
G: "C",
|
||||
C: "G",
|
||||
T: "A",
|
||||
A: "U",
|
||||
} as const;
|
||||
|
||||
type NUCLEOTIDE = keyof typeof COMPLEMENTS;
|
||||
|
||||
const nucleotides = Object.keys(COMPLEMENTS);
|
||||
|
||||
const isNucleotide = (nucleotide: string): nucleotide is NUCLEOTIDE =>
|
||||
nucleotides.includes(nucleotide);
|
||||
|
||||
export const toRna = (dnaStrand: string): string =>
|
||||
dnaStrand
|
||||
.split("")
|
||||
.map((nucleotide) => {
|
||||
if (!isNucleotide(nucleotide)) {
|
||||
throw new Error("Invalid input DNA.");
|
||||
}
|
||||
return COMPLEMENTS[nucleotide];
|
||||
})
|
||||
.join("");
|
||||
28
typescript/rna-transcription/tsconfig.json
Normal file
28
typescript/rna-transcription/tsconfig.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"display": "Configuration for Exercism TypeScript Exercises",
|
||||
"compilerOptions": {
|
||||
// Allows you to use the newest syntax, and have access to console.log
|
||||
// https://www.typescriptlang.org/tsconfig#lib
|
||||
"lib": ["ESNEXT", "dom"],
|
||||
// Make sure typescript is configured to output ESM
|
||||
// https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm
|
||||
"module": "ES2020",
|
||||
// Since this project is using babel, TypeScript may target something very
|
||||
// high, and babel will make sure it runs on your local Node version.
|
||||
// https://babeljs.io/docs/en/
|
||||
"target": "ESNext", // ESLint doesn't support this yet: "es2022",
|
||||
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
|
||||
// Because we'll be using babel: ensure that Babel can safely transpile
|
||||
// files in the TypeScript project.
|
||||
//
|
||||
// https://babeljs.io/docs/en/babel-plugin-transform-typescript/#caveats
|
||||
"isolatedModules": true
|
||||
},
|
||||
"include": ["*.ts", "*.tsx", ".meta/*.ts", ".meta/*.tsx"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user