Skip to content

Commit c66d795

Browse files
Merge pull request #4 from it-shark-pro/new-tasks
New tasks
2 parents a9b5486 + 90447e4 commit c66d795

File tree

7 files changed

+135
-22
lines changed

7 files changed

+135
-22
lines changed

.eslintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"parserOptions": {
33
"sourceType": "module"
44
},
@@ -38,4 +38,4 @@
3838
],
3939
"require-yield": 1
4040
}
41-
}
41+
}

task/04-arrays-tasks.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function generateOdds(len) {
4444

4545

4646
/**
47-
* Returns the doubled array - elements of the specified array are repeated twice
47+
* Returns the doubled array - elements of the specified array are repeated twice
4848
* using original order
4949
*
5050
* @param {array} arr
@@ -118,7 +118,7 @@ export function removeFalsyValues(arr) {
118118
* @return {array}
119119
*
120120
* @example
121-
* [ 'permanent-internship', 'glutinous-shriek', 'multiplicative-elevation' ] =>
121+
* [ 'permanent-internship', 'glutinous-shriek', 'multiplicative-elevation' ] =>
122122
* [ 'PERMANENT-INTERNSHIP', 'GLUTINOUS-SHRIEK', 'MULTIPLICATIVE-ELEVATION' ]
123123
* [ 'a', 'b', 'c', 'd', 'e', 'f', 'g' ] => [ 'A', 'B', 'C', 'D', 'E', 'F', 'G' ]
124124
*/
@@ -415,7 +415,7 @@ export function toStringList(arr) {
415415

416416

417417
/**
418-
* Sorts the specified array by country name first and city name (if countries are
418+
* Sorts the specified array by country name first and city name (if countries are
419419
* equal) in ascending order.
420420
*
421421
* @param {array} arr
@@ -538,11 +538,11 @@ export function group(array, keySelector, valueSelector) {
538538

539539

540540
/**
541-
* Projects each element of the specified array to a sequence and flattens the
541+
* Projects each element of the specified array to a sequence and flattens the
542542
* resulting sequences into one array.
543543
*
544544
* @param {array} arr
545-
* @param {Function} childrenSelector, a transform const to apply to each element
545+
* @param {Function} childrenSelector, a transform const to apply to each element
546546
* that returns an array of children
547547
* @return {array}
548548
*

task/08-objects-tasks.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function fromJSON(proto, json) {
6363
/**
6464
* Css selectors builder
6565
*
66-
* Each complex selector can consists of type, id, class, attribute, pseudo-class and
66+
* Each complex selector can consists of type, id, class, attribute, pseudo-class and
6767
* pseudo-element selectors:
6868
*
6969
* element#id.class[attr]:pseudoClass::pseudoElement
@@ -72,10 +72,10 @@ export function fromJSON(proto, json) {
7272
*
7373
* All types of selectors can be combined using the combinators ' ','+','~','>' .
7474
*
75-
* The task is to design a single class, independent classes or classes hierarchy and
75+
* The task is to design a single class, independent classes or classes hierarchy and
7676
* implement the functionality
7777
* to build the css selectors using the provided cssSelectorBuilder.
78-
* Each selector should have the stringify() method to output the string repsentation
78+
* Each selector should have the stringify() method to output the string repsentation
7979
* according to css specification.
8080
*
8181
* Provided cssSelectorBuilder should be used as facade only to create your own classes,
@@ -84,17 +84,17 @@ export function fromJSON(proto, json) {
8484
* return new MySuperBaseElementSelector(...)...
8585
* },
8686
*
87-
* The design of class(es) is totally up to you, but try to make it as simple, clear
87+
* The design of class(es) is totally up to you, but try to make it as simple, clear
8888
* and readable as possible.
8989
*
9090
* @example
9191
*
9292
* var builder = cssSelectorBuilder;
9393
*
94-
* builder.id('main').class('container').class('editable').stringify() =>
94+
* builder.id('main').class('container').class('editable').stringify() =>
9595
* '#main.container.editable'
9696
*
97-
* builder.element('a').attr('href$=".png"').pseudoClass('focus').stringify() =>
97+
* builder.element('a').attr('href$=".png"').pseudoClass('focus').stringify() =>
9898
* 'a[href$=".png"]:focus'
9999
*
100100
* builder.combine(

task/11-katas-2-tasks.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
/**
33
* Returns the bank account number parsed from specified string.
44
*
5-
* You work for a bank, which has recently purchased an ingenious machine to assist
5+
* You work for a bank, which has recently purchased an ingenious machine to assist
66
* in reading letters and faxes sent in by branch offices.
7-
* The machine scans the paper documents, and produces a string with a bank account
7+
* The machine scans the paper documents, and produces a string with a bank account
88
* that looks like this:
99
*
1010
* _ _ _ _ _ _ _
@@ -14,7 +14,7 @@
1414
* Each string contains an account number written using pipes and underscores.
1515
* Each account number should have 9 digits, all of which should be in the range 0-9.
1616
*
17-
* Your task is to write a function that can take bank account string and parse it
17+
* Your task is to write a function that can take bank account string and parse it
1818
* into actual account numbers.
1919
*
2020
* @param {string} bankAccount
@@ -42,7 +42,7 @@ export function parseBankAccount(bankAccount) {
4242

4343

4444
/**
45-
* Returns the string, but with line breaks inserted at just the right places to make
45+
* Returns the string, but with line breaks inserted at just the right places to make
4646
* sure that no line is longer than the specified column number.
4747
* Lines can be broken at word boundaries only.
4848
*
@@ -114,7 +114,7 @@ export function getPokerHandRank(hand) {
114114

115115
/**
116116
* Returns the rectangles sequence of specified figure.
117-
* The figure is ASCII multiline string comprised of minus signs -, plus signs +,
117+
* The figure is ASCII multiline string comprised of minus signs -, plus signs +,
118118
* vertical bars | and whitespaces.
119119
* The task is to break the figure in the rectangles it is made of.
120120
*

task/12-katas-3-tasks.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/**
33
* Returns true if word occurrs in the specified word snaking puzzle.
4-
* Each words can be constructed using "snake" path inside a grid with top, left,
4+
* Each words can be constructed using "snake" path inside a grid with top, left,
55
* right and bottom directions.
66
* Each char can be used only once ("snake" should not cross itself).
77
*
@@ -39,7 +39,7 @@ export function findStringInSnakingPuzzle(puzzle, searchStr) {
3939
* The order of permutations does not matter.
4040
*
4141
* @param {string} chars
42-
* @return {Iterable.<string>} all posible strings constructed with the chars from
42+
* @return {Iterable.<string>} all posible strings constructed with the chars from
4343
* the specfied string
4444
*
4545
* @example
@@ -56,9 +56,9 @@ export function* getPermutations(chars) {
5656
* Returns the most profit from stock quotes.
5757
* Stock quotes are stores in an array in order of date.
5858
* The stock profit is the difference in prices in buying and selling stock.
59-
* Each day, you can either buy one unit of stock, sell any number of stock units
59+
* Each day, you can either buy one unit of stock, sell any number of stock units
6060
* you have already bought, or do nothing.
61-
* Therefore, the most profit is the maximum difference of all pairs in a sequence
61+
* Therefore, the most profit is the maximum difference of all pairs in a sequence
6262
* of stock prices.
6363
*
6464
* @param {array} quotes

task/13-more-tasks.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Takes two strings including only letters from a to z.
3+
* Returns a new sorted string containing distinct letters.
4+
*
5+
* @param {string} value1
6+
* @param {string} value2
7+
* @return {string}
8+
*
9+
* @example
10+
* 'azy', 'bk' => 'abkyz'
11+
* 'zxxlal','laxk' => 'aklxz'
12+
* 'abcdefghijklmnop', 'lmnopqrstuvwxyz' => 'abcdefghijklmnopqrstuvwxyz'
13+
*/
14+
export function distinctLettersString(value1, value2) {
15+
/* implement your code here */
16+
throw new Error('Not implemented');
17+
}
18+
19+
20+
/**
21+
* Takes a string with any characters.
22+
* Returns an object containing appearence of every distinct letters in lower case.
23+
*
24+
* @param {string} value
25+
* @return {Object}
26+
*
27+
* @example
28+
* 'Who you are, Buddy?' => { a:1, d:2, e:1, h:1, o:2, r:1, u:2, y:2 }
29+
*
30+
*/
31+
32+
export function lowerLetters(value) {
33+
/* implement your code here */
34+
throw new Error('Not implemented');
35+
}
36+
37+
/**
38+
* Write a function that will convert a string into title case, given an optional
39+
* list of exception (minor words). The list of minor words will be given as a
40+
* string with each word separated by a space. Your function should ignore the
41+
* case of the minor words string - it should behave in the same way even if the
42+
* case of the minor word is changed
43+
*
44+
* @param {string} the original string to be converted
45+
* @param {string} list of minor words that must always be lowercase except for
46+
* the first word in the string
47+
* @return {string}
48+
*
49+
* @example
50+
* 'a clash if KINGS', 'a an the of' => 'A Clash of Kings'
51+
* 'THE WIND IN THE WILLOWS', 'The In' => 'The Wind in the Willows'
52+
* 'the quick brown fox' => 'The Quick Brown Fox'
53+
*/
54+
55+
export function titleCaseConvert(title, minorWords) {
56+
/* implement your code here */
57+
throw new Error('Not implemented');
58+
}
59+
60+
/**
61+
* Your job is to create a calculator which evaluates expressions in Reverse Polish
62+
* notation (https://en.wikipedia.org/wiki/Reverse_Polish_notation). Empty expression
63+
* should evaluate to 0. Expression without operation returns the last number.
64+
*
65+
* @param {string} RPN string, each number and operation separated by a space
66+
*
67+
* @return {Number}
68+
*
69+
* @example
70+
* '' => 0 // empty expression returns 0
71+
* '1 2 3' => 3 // expression without operation returns the last number
72+
* '4 2 +' => 6 // 4 + 2
73+
* '2 5 * 2 + 3 /' => 4 // ((5 * 2) + 2) / 3
74+
* '5 1 2 + 4 * + 3 -' => 14 // 5 + ((1 + 2) * 4) -3
75+
*/
76+
77+
export function calcRPN(expr) {
78+
/* implement your code here */
79+
throw new Error('Not implemented');
80+
}

test/13-more-tasks.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import assert from 'assert';
2+
3+
import { distinctLettersString, lowerLetters, titleCaseConvert, calcRPN } from '../task/13-more-tasks';
4+
5+
it.optional = require('../extensions/it-optional');
6+
7+
describe('13-more-tasks', () => {
8+
it.optional('distinctLettersString should return a new sorted string with distinct letters', () => {
9+
assert.equal('abcdefklmopqwxy',
10+
distinctLettersString('xyaabbbccccdefww', 'xxxxyyyyabklmopq'));
11+
assert.equal('abcdefghilnoprstu',
12+
distinctLettersString('loopingisfunbutdangerous', 'lessdangerousthancoding'));
13+
});
14+
15+
it.optional('lowerLetters should return an object of every distinct letters', () => {
16+
assert.deepEqual({ e: 2, n: 2, r: 1, t: 2 }, lowerLetters('Internet 42'));
17+
assert.deepEqual({ a: 3, d: 1, f: 2, p: 1, x: 1 }, lowerLetters('$0 af0HOE@ /xfda2 24pa'));
18+
});
19+
20+
it.optional('titleCaseConvert should return converted into title case string', () => {
21+
assert.equal('A Clash of Kings', titleCaseConvert('a clash of KINGS', 'a an the of'));
22+
assert.equal('The Wind in the Willows', titleCaseConvert('THE WIND IN THE WILLOWS', 'The In'));
23+
assert.equal('The Quick Brown Fox', titleCaseConvert('the quick brown fox'));
24+
});
25+
26+
it.optional('calcRPN should calculate Reverse Polish notation expression', () => {
27+
assert.equal(0, calcRPN(''));
28+
assert.equal(3, calcRPN('1 2 3'));
29+
assert.equal(6, calcRPN('4 2 +'));
30+
assert.equal(4, calcRPN('2 5 * 2 + 3 /'));
31+
assert.equal(14, calcRPN('5 1 2 + 4 * + 3 -'));
32+
});
33+
});

0 commit comments

Comments
 (0)