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

задачи с codewars #19

Merged
Merged
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
10 changes: 10 additions & 0 deletions codewars/Adding Big Numbers/adding_big_numbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function amount(summands) {
let first_summand = Number(summands[0]);
let second_summand = Number(summands[1]);
let summ = first_summand + second_summand;
let result_summ = String(summ);
console.log(result_summ);
}

const summands = ["123", "12"];
amount(summands);
31 changes: 31 additions & 0 deletions codewars/Anagram difference/anagram_difference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function count_sort(str) {
let str_index = [];
for (let i = 0; i < str.length; i++) {
str_index[i] = str.charCodeAt(i) - str.charCodeAt('a');
}

let count_str = new Array(26);

for (i of str_index) {
tmp = (count_str[i] ?? 0) + 1;
count_str[i] = tmp;

}
return count_str;
}


function anagrams(str_1, str_2) {
let count_str_1 = count_sort(str_1);
let count_str_2 = count_sort(str_2);
let anagram = 0;
for (i = 0; i < 26; i ++) {
anagram = anagram + Math.abs((count_str_1[i] ?? 0) - (count_str_2[i] ?? 0));
}
console.log(anagram);
}

const str_1 = 'codewars';
const str_2 = 'hackerrank';
anagrams(str_1, str_2);

6 changes: 6 additions & 0 deletions codewars/Array Deep Count/array_deep_count.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function deepCount(a){
return a.reduce((s,e)=>s+(Array.isArray(e)?deepCount(e):0),a.length);
}

const a = [1, 2, [3, 4, [5]]];
console.log(deepCount(a));
18 changes: 18 additions & 0 deletions codewars/Build Tower/build_tower.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function tower(floors) {
let res_tower = new Array(floors);
let places = floors * 2 - 1;
for (i = 1; i <= floors; i ++) {
count_whiteplace = floors - i;
count_asterisk = places - (floors - i) * 2;
whiteplace = ' '.repeat(count_whiteplace);
asterisk = '*'.repeat(count_asterisk);
str = whiteplace + asterisk + whiteplace;
res_tower[i - 1] = str;
}
for (j = 0; j < floors; j ++) {
console.log(res_tower[j]);
}
}

let floors = 9;
tower(floors);
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function convert (str){
let str_new = "";
for (i = 0; i < str.length; i++) {
if (str[i] === "-") {
let letter = str[i+1].toUpperCase();
str_new = str_new.concat(letter);
i = i + 2;
}
str_new = str_new.concat(str[i]);
}
console.log(str_new);
}

const str_ex = "the-stealth-warrior";
convert(str_ex);
23 changes: 23 additions & 0 deletions codewars/Duplicate Encoder/duplicate_encoder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function transformation(exemple_string) {
for (let i = 0; i < exemple_string.length + 1; i++) {
let letter = exemple_string[i];
let count = 0;
let new_string = '';
for (let j = 0; j < exemple_string.length + 1; i++) {
if (letter == exemple_string[j]) {
count ++;
}
}
if (count === 1) {
new_string = new_string + '(';
}
else {
new_string = new_string + ')';
}

}
console.log(new_string);
}

let a = 'recede';
transformation(a);
18 changes: 18 additions & 0 deletions codewars/Find the missing letter/find_the_missing_letter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function missing_letter(arr, len) {
for (i = 0; i < len; i ++) {
let letters = arr[i];
arr[i] = letters.charCodeAt();
}
for (i = 0; i < len - 1; i++) {
if ((arr[i + 1] - arr[i]) != 1) {
let numb = arr[i] + 1;
let letter = String.fromCharCode(numb);
console.log(letter);
}
}

}

const arr_ex = ["a","b","c", "e", "f", "h"];
const len = arr_ex.length;
missing_letter(arr_ex, len);
5 changes: 5 additions & 0 deletions codewars/Fun with tree - max sum/fun_with_trees_max_sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function maxSum(root) {
if (!root) return 0
return root.value + Math.max(maxSum(root.left),maxSum(root.right))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function Node(data, nxt) {
this.data = data;
this.next = nxt;
}
function sortedInsert(head, data) {
if(!head || data < head.data) return new Node(data, head);
else {
head.next = sortedInsert(head.next, data);
return head;
}
}

13 changes: 13 additions & 0 deletions codewars/Merge two arrays/merge_two_arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function mergeArrays(a, b) {
const arr=[];
let l = Math.max(a.length,b.length)
for (let i=0; i < l; i++){
arr.push(a[i])
arr.push(b[i])
}
return arr.filter(v=>v!==undefined)
}

const a = ["a", "b", "c", "d", "e"];
const b = [1, 2, 3, 4, 5];
console.log(mergeArrays(a, b));
16 changes: 16 additions & 0 deletions codewars/Moving Zeros To The End/moving_zeros_to_the_end.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function bubble_sort(arr, len) {
zero = Number(0);
for (i = 0; i < len; i ++) {
for (j = 0; j < (len - i - 1); j++) {
if (arr[j] === zero) {
arr[j] = arr[j+1];
arr[j+1] = zero;
}
}
}
console.log(arr)
}

arr = [false,1,0,1,2,0,1,3,"a"];
len = arr.length
bubble_sort(arr, len);
17 changes: 17 additions & 0 deletions codewars/Simple Pig Latin/simple_pig_latin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function pigConvert(str) {
let new_str = "";
for (word of str) {
let end_letter = word[0];
console.log(word[0]);
console.log(word.length);
console.log(word);
for (i = 0; i < word.length; i++) {
new_str = new_str.contact(word[i+1]);
}
new_str = new_str.contact(end_letter);
}
console.log(new_str);
}

const str_ex = "Pig latin is cool";
pigConvert(str_ex);
34 changes: 34 additions & 0 deletions rpgsaga/saga/src/class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
enum Types {DOCX = "docx" , PPTX = "pptx", PNG = "png"};

class Documents {

name: string
type: string
size: number

constructor(name, type, size) {
this.name = name
this.type = type
this.size = size
}

getName() {
return this.name
}

nameContains(str) {
return this.getName().includes(str)
}

getType() {
return this.type
}

getSize() {
return (this.size + ' Кб')
}

}

const doc = new Documents('Реферат', Types.DOCX, 15)
console.log(doc.getName())
Loading