diff --git a/codewars/Adding Big Numbers/adding_big_numbers.js b/codewars/Adding Big Numbers/adding_big_numbers.js new file mode 100644 index 0000000..056ce90 --- /dev/null +++ b/codewars/Adding Big Numbers/adding_big_numbers.js @@ -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); \ No newline at end of file diff --git a/codewars/Anagram difference/anagram_difference.js b/codewars/Anagram difference/anagram_difference.js new file mode 100644 index 0000000..75dd2e3 --- /dev/null +++ b/codewars/Anagram difference/anagram_difference.js @@ -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); + diff --git a/codewars/Array Deep Count/array_deep_count.js b/codewars/Array Deep Count/array_deep_count.js new file mode 100644 index 0000000..07389af --- /dev/null +++ b/codewars/Array Deep Count/array_deep_count.js @@ -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)); \ No newline at end of file diff --git a/codewars/Build Tower/build_tower.js b/codewars/Build Tower/build_tower.js new file mode 100644 index 0000000..723b446 --- /dev/null +++ b/codewars/Build Tower/build_tower.js @@ -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); \ No newline at end of file diff --git a/codewars/Convert string to camel case/convert_string_to_camel_case.js b/codewars/Convert string to camel case/convert_string_to_camel_case.js new file mode 100644 index 0000000..c3ee92e --- /dev/null +++ b/codewars/Convert string to camel case/convert_string_to_camel_case.js @@ -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); \ No newline at end of file diff --git a/codewars/Duplicate Encoder/duplicate_encoder.js b/codewars/Duplicate Encoder/duplicate_encoder.js new file mode 100644 index 0000000..5d7ae5b --- /dev/null +++ b/codewars/Duplicate Encoder/duplicate_encoder.js @@ -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); diff --git a/codewars/Find the missing letter/find_the_missing_letter.js b/codewars/Find the missing letter/find_the_missing_letter.js new file mode 100644 index 0000000..f23e46b --- /dev/null +++ b/codewars/Find the missing letter/find_the_missing_letter.js @@ -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); \ No newline at end of file diff --git a/codewars/Fun with tree - max sum/fun_with_trees_max_sum.js b/codewars/Fun with tree - max sum/fun_with_trees_max_sum.js new file mode 100644 index 0000000..0ea81cc --- /dev/null +++ b/codewars/Fun with tree - max sum/fun_with_trees_max_sum.js @@ -0,0 +1,5 @@ +function maxSum(root) { + if (!root) return 0 + return root.value + Math.max(maxSum(root.left),maxSum(root.right)) +} + diff --git a/codewars/Linked Lists - Sorted Insert/linked_lists_sorted_insert.js b/codewars/Linked Lists - Sorted Insert/linked_lists_sorted_insert.js new file mode 100644 index 0000000..43e9e56 --- /dev/null +++ b/codewars/Linked Lists - Sorted Insert/linked_lists_sorted_insert.js @@ -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; + } +} + diff --git a/codewars/Merge two arrays/merge_two_arrays.js b/codewars/Merge two arrays/merge_two_arrays.js new file mode 100644 index 0000000..ece1846 --- /dev/null +++ b/codewars/Merge two arrays/merge_two_arrays.js @@ -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)); \ No newline at end of file diff --git a/codewars/Moving Zeros To The End/moving_zeros_to_the_end.js b/codewars/Moving Zeros To The End/moving_zeros_to_the_end.js new file mode 100644 index 0000000..98989a0 --- /dev/null +++ b/codewars/Moving Zeros To The End/moving_zeros_to_the_end.js @@ -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); \ No newline at end of file diff --git a/codewars/Simple Pig Latin/simple_pig_latin.js b/codewars/Simple Pig Latin/simple_pig_latin.js new file mode 100644 index 0000000..9cc2ff5 --- /dev/null +++ b/codewars/Simple Pig Latin/simple_pig_latin.js @@ -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); \ No newline at end of file diff --git a/rpgsaga/saga/src/class.ts b/rpgsaga/saga/src/class.ts new file mode 100644 index 0000000..f108854 --- /dev/null +++ b/rpgsaga/saga/src/class.ts @@ -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())