Skip to content

Commit 29b4ecb

Browse files
committed
initial upload
1 parent 89b83c6 commit 29b4ecb

8 files changed

+169
-2
lines changed

1LanguageSpecifics/AMinerTask.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function main(input) {
2+
3+
let resources = new Map();
4+
let i = 0;
5+
let product = input[i];
6+
7+
while (product !== 'stop') {
8+
9+
let quantity = parseInt(input[i + 1]);
10+
11+
if (resources.has(product)) {
12+
13+
let prevQuantity = resources.get(product);
14+
resources.set(product, prevQuantity + quantity);
15+
}
16+
else {
17+
18+
resources.set(product, quantity);
19+
}
20+
21+
i += 2;
22+
product = input[i];
23+
}
24+
25+
for (resource of resources) {
26+
27+
console.log('%s -> %s', resource[0], resource[1]);
28+
}
29+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function main(input) {
2+
3+
let n = parseInt(input[0]);
4+
5+
let phrases = ["Excellent product.", "Such a great product.", "I always use that product.", "Best product of its category.", "Exceptional product.", "I can’t live without this product."];
6+
let events = ["Now I feel good.", "I have succeeded with this product.", "Makes miracles.I am happy of the results!", "I cannot believe but now I feel awesome.", "Try it yourself, I am very satisfied.", "I feel great!"];
7+
let authors = ["Diana", "Petya", "Stella", "Elena", "Katya", "Iva", "Annie", "Eva"];
8+
let cities = ["Burgas", "Sofia", "Plovdiv", "Varna", "Ruse"];
9+
10+
for (i = 0; i < n; i++) {
11+
12+
let randomPhrase = phrases[Math.floor((Math.random() * phrases.length))];
13+
let randomEvent = events[Math.floor((Math.random() * events.length))];
14+
let randomAuthor = authors[Math.floor((Math.random() * authors.length))];
15+
let randomCity = cities[Math.floor((Math.random() * cities.length))];
16+
17+
console.log("%s %s %s - %s", randomPhrase, randomEvent, randomAuthor, randomCity);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function main(input) {
2+
3+
let text = input[0].toLowerCase();
4+
if (input[1] == undefined) {
5+
6+
var pattern = ' ';
7+
}
8+
else {
9+
10+
pattern = input[1].toLowerCase();
11+
}
12+
13+
let counter = 0;
14+
let index = text.indexOf(pattern);
15+
16+
while (index != -1) {
17+
18+
counter++;
19+
index = text.indexOf(pattern, index + 1);
20+
}
21+
22+
console.log(counter);
23+
}

1LanguageSpecifics/ExtractEmails.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function main(input) {
2+
3+
let text = input[0];
4+
const pattern = /(?:^| )([a-z][a-z0-9\-\._]+@[a-z0-9\-]+(\.[a-z0-9\-]+){1,})/g;
5+
6+
let matches = text.match(pattern);
7+
8+
if (matches != null) {
9+
10+
for (let match of matches) {
11+
console.log(match.trim());
12+
}
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function main(input) {
2+
3+
let keyword = input[0];
4+
const delimitersForSentences = /[\.\?\!]/g;
5+
let sentences = input[1].split(delimitersForSentences);
6+
const delimitersForWords = /\W/g;
7+
8+
let results = [];
9+
10+
for (i = 0; i < sentences.length; i++) {
11+
12+
let words = sentences[i].split(delimitersForWords);
13+
14+
for (j = 0; j < words.length; j++) {
15+
16+
if (words[j] === keyword) {
17+
18+
results.push(sentences[i]);
19+
}
20+
}
21+
}
22+
23+
for (i = 0; i < results.length; i++) {
24+
25+
console.log(results[i].trim());
26+
}
27+
}

1LanguageSpecifics/Phonebook.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function main(input) {
2+
3+
let i = 0;
4+
let command = input[i].split(' ');
5+
let phonebook = new Map();
6+
7+
while (command[0] !== "END") {
8+
9+
switch (command[0]) {
10+
11+
case 'A':
12+
var name = command[1];
13+
let phone = command[2];
14+
phonebook.set(name, phone);
15+
break;
16+
17+
case 'S':
18+
name = command[1];
19+
20+
if (phonebook.has(name)) {
21+
22+
console.log("%s -> %s", name, phonebook.get(name));
23+
}
24+
else {
25+
26+
console.log("Contact %s does not exist.", name);
27+
}
28+
break;
29+
30+
default:
31+
break;
32+
}
33+
34+
i++;
35+
command = input[i].split(' ');
36+
}
37+
}

1LanguageSpecifics/SumReversedNumbers.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
function main(input) {
22

3+
let numbers = input[0].split(' ');
34
let sum = 0;
45

5-
for (i = 0; i < input.length; i++) {
6+
for (i = 0; i < numbers.length; i++) {
67

7-
let numCharArrRev = input[i].split('').reverse().join('');
8+
let numCharArrRev = numbers[i].split('').reverse().join('');
89
sum += parseInt(numCharArrRev);
910
}
1011

1LanguageSpecifics/TextFilter.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function main(input) {
2+
3+
let bannedWords = input[0].split(", ");
4+
let text = input[1];
5+
6+
for (i = 0; i < bannedWords.length; i++) {
7+
8+
if (text.includes(bannedWords[i])) {
9+
10+
let replacement = new Array(bannedWords[i].length + 1).join('*');
11+
let bannedWord = new RegExp(bannedWords[i], 'g');
12+
text = text.replace(bannedWord, replacement);
13+
}
14+
}
15+
16+
console.log(text);
17+
}

0 commit comments

Comments
 (0)