-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alena648
committed
Oct 17, 2023
1 parent
c8965a3
commit c5d7cea
Showing
13 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
15 changes: 15 additions & 0 deletions
15
codewars/Convert string to camel case/convert_string_to_camel_case.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
codewars/Find the missing letter/find_the_missing_letter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
codewars/Linked Lists - Sorted Insert/linked_lists_sorted_insert.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
codewars/Moving Zeros To The End/moving_zeros_to_the_end.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |