Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate tests to native runner #159

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 AlreadyBored
Copyright (c) 2023 AlreadyBored

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
113 changes: 69 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
---

#### Prerequisites
1. Install [Node.js](https://nodejs.org/en/download/)

1. Install [Node.js](https://nodejs.org/en/download/)
2. Fork this repository: https://github.com/AlreadyBored/basic-js
3. Clone your newly created repo: https://github.com/<%your_github_username%>/basic-js/
4. Go to folder `basic-js`
5. To install all dependencies use [`npm install`](https://docs.npmjs.com/cli/install)
3. Clone your newly created repo: https://github.com/<%your_github_username%>/basic-js/
4. Go to folder `basic-js`
5. To install all dependencies use [`npm install`](https://docs.npmjs.com/cli/install)
6. Run `npm run test` in command line.
7. You will see the number of pending, passing and failing tests. 100% of passing tests is equal to max score for the task

---

#### Troubleshooting

- If you catch error like [this](https://user-images.githubusercontent.com/17920285/158375305-f54d87fa-6f42-402f-af25-10b233d98cf9.png) you can try to make `npm install -g node-gyp`

---

#### Submit to [rs app](https://app.rs.school)

1. Open [rs app](https://app.rs.school) and login
2. Go to submit task page
3. Select your task (BasicJS)
Expand All @@ -29,12 +32,14 @@
---

#### Notes

1. We recommend you to use Node.js of version 16.x.x LTS. If you use any of features, that does not supported by Node.js v16, there may be problems with task submit.
2. Please, be sure that each of your tests is limited to 30 sec.

---

## General task description

Your task is to write several functions that are the solution to the subtasks. Subtasks descriptions, as well as instructions on how to run tests and submit solutions are below.

---
Expand Down Expand Up @@ -65,11 +70,12 @@ To determine the age of archaeological finds, **radioisotope dating** is widely

The approximate age of the sample is calculated by measuring the **ratio** of the **modern** activity of the C14 isotope to the activity of the same isotope in the **sample**.

[Read about method](https://chem.libretexts.org/Bookshelves/Physical_and_Theoretical_Chemistry_Textbook_Maps/Supplemental_Modules_(Physical_and_Theoretical_Chemistry)/Nuclear_Chemistry/Nuclear_Kinetics/Half-Lives_and_Radioactive_Decay_Kinetics#section_2)
[Read about method](<https://chem.libretexts.org/Bookshelves/Physical_and_Theoretical_Chemistry_Textbook_Maps/Supplemental_Modules_(Physical_and_Theoretical_Chemistry)/Nuclear_Chemistry/Nuclear_Kinetics/Half-Lives_and_Radioactive_Decay_Kinetics#section_2>)

[Reserved link](https://web.archive.org/web/20230522040038/https://chem.libretexts.org/Bookshelves/Physical_and_Theoretical_Chemistry_Textbook_Maps/Supplemental_Modules_%28Physical_and_Theoretical_Chemistry%29/Nuclear_Chemistry/Nuclear_Kinetics/Half-Lives_and_Radioactive_Decay_Kinetics#section_2)

---

<details>

<summary>About calculations</summary>
Expand Down Expand Up @@ -122,6 +128,7 @@ Your task is to implement the function `getSeason(date)` that accepts `Date` obj
Time of the year must be `string`.

---

<details>

<summary>Seasons in English</summary>
Expand Down Expand Up @@ -155,18 +162,20 @@ Write your code in `src/what-season.js`.
It consists of three rods and a number of disks of different sizes, which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.

The objective of the puzzle is to move the entire stack to another rod, obeying the following simple **rules**:
* Only **one** disk can be moved at a time.
* Each move consists of taking the **upper** disk from one of the stacks and placing it on **top** of another stack or on an empty rod.
* No **larger** disk may be placed on top of a **smaller** disk.

- Only **one** disk can be moved at a time.
- Each move consists of taking the **upper** disk from one of the stacks and placing it on **top** of another stack or on an empty rod.
- No **larger** disk may be placed on top of a **smaller** disk.

Your task is much easier than coming up with an algorithm that solves this puzzle :)

Implement the function `calculateHanoi` that accepts `diskNumber` and `turnsSpeed` parameters. `diskNumber` is a number of **disks** and `turnsSpeed` is the speed of moving discs (in **turns** per **hour**).
Both parameters are `numbers`.

`calculateHanoi` function returns an object with 2 properties:
* `turns` (minimum `number` of turns to solve the puzzle)
* `seconds` (minimum `number` of **seconds** to solve the puzzle at a given `turnsSpeed`, seconds must be an integer, obtained from **rounded down** (floor) calculation result)

- `turns` (minimum `number` of turns to solve the puzzle)
- `seconds` (minimum `number` of **seconds** to solve the puzzle at a given `turnsSpeed`, seconds must be an integer, obtained from **rounded down** (floor) calculation result)

You don't need to validate parameters.

Expand All @@ -183,10 +192,11 @@ Write your code in `src/hanoi-tower.js`.
![Transform array](https://www.capturehighered.com/wp-content/uploads/2019/02/The-Call-720x332.jpg)
Your task is to implement the function `transform(arr)` that takes an `array` and returns **transformed** array, based on the **control sequences** that `arr` contains.
**Control sequences** are defined `string` elements of the mentioned `array`:
* `--discard-next` excludes the next element of the array from the transformed array.
* `--discard-prev` excludes the previous element of the array from the transformed array.
* `--double-next` duplicates the next element of the array in the transformed array.
* `--double-prev` duplicates the previous element of the array in the transformed array.

- `--discard-next` excludes the next element of the array from the transformed array.
- `--discard-prev` excludes the previous element of the array from the transformed array.
- `--double-next` duplicates the next element of the array in the transformed array.
- `--double-prev` duplicates the previous element of the array in the transformed array.

For example:

Expand All @@ -207,11 +217,12 @@ Let's practice in [chaining](https://en.wikipedia.org/wiki/Method_chaining)!

Your task is to create the object `chainMaker` that creates chains. The finished chain is a `string` and looks like this: `'( value1 )~~( value2 )~~( value3 )'`.
The `chainMaker` has several **methods** for creating chains and modifying them:
* `getLength` returns the current chain length as a number;
* `addLink(value)` adds a link containing a `string` representation of the `value` to the chain;
* `removeLink(position)` removes a chain link in the specified position;
* `reverseChain` reverses the chain;
* `finishChain` ends the chain and `returns` it.

- `getLength` returns the current chain length as a number;
- `addLink(value)` adds a link containing a `string` representation of the `value` to the chain;
- `removeLink(position)` removes a chain link in the specified position;
- `reverseChain` reverses the chain;
- `finishChain` ends the chain and `returns` it.

`addLink`, `reverseChain` and `removeLink` methods are **chainable**, while the another ones are not. If `addLink` is called with no arguments, it adds an empty link (`'( )'`) to the chain. If `removeLink` accepts **invalid** `position` (e.g. not a number, or a fractional number, or corresponding to a nonexistent link), it must throw an `Error` with message `You can't remove incorrect link!`. After calling the `finishChain` method, the existing chain must be deleted, as if an `Error` was thrown.

Expand Down Expand Up @@ -247,22 +258,24 @@ For example:
Write your code in `src/recursive-depth.js`.

---

### **Extended repeater**

![Extended repater](https://upload.wikimedia.org/wikipedia/commons/4/4b/Macaws_at_Jurong_Bird_Park_-Singapore-8.jpg)
Your task is to implement the function `repeater(str, options)`.
This function returns a repeating `string` based on the given parameters:
* `str` is a `string` to repeat;
* `options` is an `object` of options, that contains properties:
* `repeatTimes` sets the `number` of repetitions of the `str`;
* `separator` is a `string` separating repetitions of the `str`;
* `addition` is an additional `string` that will be added to each repetition of the `str`;
* `additionRepeatTimes` sets the `number` of repetitions of the `addition`;
* `additionSeparator` is a `string` separating repetitions of the `addition`.

- `str` is a `string` to repeat;
- `options` is an `object` of options, that contains properties:
- `repeatTimes` sets the `number` of repetitions of the `str`;
- `separator` is a `string` separating repetitions of the `str`;
- `addition` is an additional `string` that will be added to each repetition of the `str`;
- `additionRepeatTimes` sets the `number` of repetitions of the `addition`;
- `additionSeparator` is a `string` separating repetitions of the `addition`.

The `str` and `addition` parameters are `strings` by default. In case when **type** of these parameters is different, they must be converted to a `string`.

`separator` and `additionSeparator` parameters are `strings`.
`separator` and `additionSeparator` parameters are `strings`.

`repeatTimes` and `additionRepeatTimes` are integer `numbers` (in the absence of any of them, the corresponding string is not repeated).

Expand All @@ -282,7 +295,7 @@ Cryptography is awesome! Let's try to organize production of encryption machines
Our machine will have 2 modifications: **direct** and **reverse** (the type of machine is determined at the moment of creation). The **direct** machine simply encodes and decodes the string that was transmitted to it, and the **reverse** machine returns an **inverted** string after encoding and decoding.

Your task is to implement the class `VigenereCipheringMachine`. `constructor` of this `class` accepts `true` (**or nothing**) to create **direct** machine and `false` to create **reverse** machine.
Each instance of `VigenereCipheringMachine` must have 2 methods: `encrypt` and `decrypt`.
Each instance of `VigenereCipheringMachine` must have 2 methods: `encrypt` and `decrypt`.

`encrypt` method accepts 2 parameters: `message` (`string` to encode) and `key` (`string`-keyword).

Expand Down Expand Up @@ -311,6 +324,7 @@ Write your code in `src/vigenere-cipher.js`.
---

### **(ST) Common character count**

Your task is to implement function that accepts two **strings** (`s1` and `s2`) and returns **number** of common characters between them.

For example:
Expand All @@ -322,6 +336,7 @@ Write your code in `src/common-character-count.js`.
---

### **(ST) Delete digit**

Your task is to implement function that accepts **integer number** (`n`) and returns maximal **number** you can obtain by deleting exactly one digit of the given number.

For example:
Expand All @@ -333,6 +348,7 @@ Write your code in `src/delete-digit.js`.
---

### **(ST) DNS stat**

Your task is to implement function that accepts an **array** of domains (`domains`) and returns the **object** with the appearances of the DNS.

For example:
Expand All @@ -344,6 +360,7 @@ Write your code in `src/dns-stats.js`.
---

### **(ST) Encode line**

Your task is to implement function that accepts **string** (`str`) and returns its encoded version.

For example:
Expand All @@ -355,6 +372,7 @@ Write your code in `src/encode-line.js`.
---

### **(ST) File names**

There's a list of file, since two files cannot have equal names, the one which comes later will have a suffix **(k)**, where k is the smallest **integer** such that the found name is not used yet.
Your task is to implement function that accepts **array** of names (`names`) and returns an **array** of names that will be given to the files.

Expand All @@ -367,7 +385,8 @@ Write your code in `src/file-names.js`.
---

### **(ST) Get email domain**
Your task is to implement function that accepts email address (`email`) and returns it's **domain**.

Your task is to implement function that accepts email address (`email`) and returns it's **domain**.

For example:

Expand All @@ -378,8 +397,9 @@ Write your code in `src/get-email-domain.js`.
---

### **(ST) Is MAC-48 Address?**

The **MAC-48 address** is six groups of two hexadecimal digits (0 to 9 or A to F) separated by hyphens.
Your task is to implement function that accepts **string** (`inputString`) and returns `true` if **string** is valid **MAC-48 address**.
Your task is to implement function that accepts **string** (`inputString`) and returns `true` if **string** is valid **MAC-48 address**.

For example:

Expand All @@ -390,6 +410,7 @@ Write your code in `src/mac-adress.js`.
---

### **(ST) Matrix elements sum**

Given **matrix**, a rectangular matrix of **integers**, just add up all the values that **don't appear below a "0"**.

For example:
Expand All @@ -409,6 +430,7 @@ Write your code in `src/matrix-elements-sum.js`.
---

### **(ST) Minesweeper**

In the popular Minesweeper game you have a board with some mines and cells that have a **number** in it that indicates the total **number of mines** in the neighboring cells. Starting off with some arrangement of mines we want to create a Minesweeper game setup.

For example:
Expand All @@ -427,11 +449,12 @@ minesweeper(matrix) => [
];
```

Write your code in `src/mine-sweeper.js`.
Write your code in `src/minesweeper.js`.

---

### **(ST) Sort by height**

Given an array with heights, sort them except if the value is `-1`.
Your task is to implement function that accepts **array** (`arr`) and returns it **sorted**

Expand All @@ -444,7 +467,8 @@ Write your code in `src/sort-by-height.js`.
---

### **(ST) Sum digits**
Your task is to implement function that accepts a **number** (`n`) and returns the **sum of its digits** until we get to a **one digit number**.

Your task is to implement function that accepts a **number** (`n`) and returns the **sum of its digits** until we get to a **one digit number**.

For example:

Expand All @@ -458,20 +482,21 @@ Write your code in `src/sum-digits.js`.

---

© [AlreadyBored](https://github.com/alreadybored)
© [AlreadyBored](https://github.com/alreadybored)

& tasks:
* Common character count
* Delete digit
* DNS stat
* Encode line
* File names
* Get email domain
* Is MAC-48 Adress?
* Matrix elements sum
* Minesweeper
* Sort by height
* Sum digits

- Common character count
- Delete digit
- DNS stat
- Encode line
- File names
- Get email domain
- Is MAC-48 Adress?
- Matrix elements sum
- Minesweeper
- Sort by height
- Sum digits

are integrated from [Short track 2021 repo](https://github.com/rkhaslarov/rs-school-short-track-2021)

Expand Down
Loading