Skip to content
Open
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
21 changes: 21 additions & 0 deletions codewars/Adding Big Numbers/1zad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function addbignumbbignumb(a, b) {
while (a.length < b.length) a = '0' + a;
while (b.length < a.length) b = '0' + b;

let carr = 0;
let result = '';

for (let i = a.length - 1; i >= 0; i--) {
let sum = parseInt(a[i]) + parseInt(b[i]) + carr;
carr = Math.floor(sum / 10);
result = (sum % 10) + result;
}
if (carr > 0) {
result = carr + result;
}

return result;
}

let result = addbignumbbignumb("12331321134145151351", "32123414321424124312341242");
console.log(result);
30 changes: 30 additions & 0 deletions codewars/Anagram difference/2zad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function smr(word, wb2) {
for (let j = 0; j < wb2.length; j++) {
if (word === wb2[j]) {
wb2.splice(j, 1);
return word;
}
}
return null;
}

function anargramDif(w1, w2) {
let wb1 = w1.split("");
let wb2 = w2.split("");
let box_of_repeat = [];

for (let i = 0; i < wb1.length; i++) {
let res_word = smr(wb1[i], wb2);
if (res_word !== null) {
box_of_repeat.push(res_word);
wb1.splice(i, 1);
i--;
}
}

let final_result = (wb1.length + wb2.length);
return final_result;
}

let result = anargramDif("codewars", "hackerrank");
console.log(result);
24 changes: 24 additions & 0 deletions codewars/Array Deep Count/3zad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function adc(word){
if (Array.isArray(word)) {
console.log("yes");
let count = Count(word);
return count + 1;
}
else {
console.log("no");
return(1);
}
}


function Count(is_here_anyobj){
let Global_count = 0;
for (let i = 0; i < is_here_anyobj.length; i++){
let pre_res = adc(is_here_anyobj[i]);
Global_count += pre_res;
}
return(Global_count);
}
let arr = [1, 2, 3];
let result = Count(arr);
console.log(result);
18 changes: 18 additions & 0 deletions codewars/Build Tower/4zad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function TowerMaker(number_of_blocks){
let pyrimidecanvas = [];
let number_of_space = number_of_blocks - 1;
let counting_stars = 1;
for (let i = 0; i < number_of_blocks; i++){
let floor_pyrimidecanvas = ' '.repeat(number_of_space) + "*".repeat(counting_stars) + ' '.repeat(number_of_space);
pyrimidecanvas.push(floor_pyrimidecanvas);
counting_stars += 2;
number_of_space -=1;
}
return(pyrimidecanvas);
}

let pyrimidecanvas_floor = TowerMaker(5);

let formattedpyrimidecanvas = '[\n ' + pyrimidecanvas_floor.map(line => `"${line}"`).join(',\n ') + '\n]';

console.log(formattedpyrimidecanvas);
16 changes: 16 additions & 0 deletions codewars/Convert string to camel case/5zad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function CS(str){
let result = "";
for (i = 0; i < str.length; i++) {
if (str[i] == "-" || str[i] == "_") {
i++;
result += str[i].toUpperCase();
}
else{
result += str[i];
}
}
return(result);
}

let guess_word = CS("the-stealth_warrior");
console.log(guess_word);
24 changes: 24 additions & 0 deletions codewars/Duplicate Encoder/6zad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function duplicateEncode(word){
let splitword = word.toLowerCase().split('');

let convertext = [];

for (let i = 0; i < splitword.length; i++) {
let count = 0;
for (let j = 0; j < splitword.length; j++){
if (splitword[i] === splitword[j]){
count++;
}
}
if (count > 1) {
convertext.push(")");
} else {
convertext.push("(");
}
}

return convertext.join('');
}

let result = duplicateEncode("dir");
console.log(result);
17 changes: 17 additions & 0 deletions codewars/Find the missing letter/7zad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function Findmissletter(array)
{
for (let i = 0; i < array.length; i++) {
let currentCharCode = array[i].charCodeAt(0);
let nextCharCode = array[i+1].charCodeAt(0);

if (nextCharCode !== currentCharCode + 1){
return String.fromCharCode(currentCharCode + 1);
}
}
}



let arr = ["b", "c", "e"];
let result = Findmissletter(arr);
console.log(result);
33 changes: 33 additions & 0 deletions codewars/Flatten a Nested Map/8zad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function flattenaNestedMap(map, keys = '', res = {}) {
let temp_massiv_map = Object.keys(map);

if (temp_massiv_map.length === 0) {
return res;
}

for (let i = 0; i < temp_massiv_map.length; i++) {
let key = temp_massiv_map[i];
let newKey = keys ? `${keys}/${key}` : key;

if (typeof map[key] === 'object' && map[key] !== null && !Array.isArray(map[key])) {
flattenaNestedMap(map[key], newKey, res);
} else {
res[newKey] = map[key];
}
}

return res;
}

let mops = {
'a': {
'b': {
'c': 12,
'd': 'Hello World'
},
'e': [1, 2, 3]
}
};

let result = flattenaNestedMap(mops);
console.log(result);
30 changes: 30 additions & 0 deletions codewars/Fun with tree - max sum/9zad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function havefunwithtree(root) {
if (root === null) {
return 0;
}

if (root.left === null && root.right === null) {
return root.value;
}

const leftSum = root.left ? havefunwithtree(root.left) : -Infinity;
const rightSum = root.right ? havefunwithtree(root.right) : -Infinity;

return root.value + Math.max(leftSum, rightSum);
}

const tree1 = new TreeNode(
17,
new TreeNode(3, new TreeNode(2)),
new TreeNode(-10, new TreeNode(16), new TreeNode(1, new TreeNode(13)))
);

console.log(havefunwithtree(tree1));

const tree2 = new TreeNode(
5,
new TreeNode(4, new TreeNode(-80), new TreeNode(-60)),
new TreeNode(10, new TreeNode(-90))
);

console.log(havefunwithtree(tree2));
56 changes: 56 additions & 0 deletions codewars/Linked Lists - Sorted Insert/10zad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class Node {
constructor(data) {
this.data = data;
this.next = null;
}
}

function sortins(head, data) {
let newNode = new Node(data);

if (!head || data < head.data) {
newNode.next = head;
return newNode;
}

let current = head;
while (current.next && current.next.data < data) {
current = current.next;
}

newNode.next = current.next;
current.next = newNode;

return head;
}

function printLinkedlist(head) {
let current = head;
let result = [];
while (current) {
result.push(current.data);
current = current.next;
}
console.log(result.join(' -> '));
}

let list1 = new Node(1);
list1.next = new Node(2);
list1.next.next = new Node(3);

let newHead1 = sortins(list1, 4);
printLinkedlist(newHead1);

let list2 = new Node(1);
list2.next = new Node(7);
list2.next.next = new Node(8);

let newHead2 = sortins(list2, 5);
printLinkedlist(newHead2);

let list3 = new Node(3);
list3.next = new Node(5);
list3.next.next = new Node(9);

let newHead3 = sortins(list3, 7);
printLinkedlist(newHead3);
19 changes: 19 additions & 0 deletions codewars/Merge two arrays/11zad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function mergeAr(a, b) {
let box = [];
for (let i = 0; i < a.length; i++){
if(i >= a.length){
box.push(b[i]);
}
else if(i >= b.length){
box.push(a[i]);
}
else{
box.push(a[i]);
box.push(b[i]);
}
}
return(box);
}

let result = mergeAr(["a", "b", "c", "d", "e", "f"], [1, 2, 3]);
console.log(result);
17 changes: 17 additions & 0 deletions codewars/Moving Zeros To The End/12zad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function movingZerostoTheEnd(arr) {
let arwz = [];
let arrzero = [];
for (let i = 0; i < arr.length; i++){
if (arr[i] === 0){
arrzero.push(arr[i]);
}
else{
arwz.push(arr[i]);
}
}
return arwz.concat(arrzero);
}


result = movingZerostoTheEnd([false,1,0,1,2,0,1,3,"a"]);
console.log(result);
26 changes: 26 additions & 0 deletions codewars/Permutations/13zad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function permutations(str) {
if (str.length <= 1) {
return [str];
}

const resultSet = new Set();

for (let i = 0; i < str.length; i++) {
const char = str[i];
const remainingChars = str.slice(0, i) + str.slice(i + 1);
const remainingPermutations = permutations(remainingChars);

for (const perm of remainingPermutations) {
resultSet.add(char + perm);
}
}

return Array.from(resultSet);
}

const input = "aabb";
const permutationsut = permutations(input);

const formattedOutput = permutationsut.map(permutations => `'${permutations}'`);

console.log(`[${formattedOutput.join(', ')}]`);
19 changes: 19 additions & 0 deletions codewars/Product of consecutive Fib numbers/14zad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function Fubnumbers(prod) {
let a = 0;
let b = 1;

while (a * b < prod) {
let next = a + b;
a = b;
b = next;
}

if (a * b === prod) {
return [a, b, true];
} else {
return [a, b, false];
}
}

console.log(Fubnumbers(714));
console.log(Fubnumbers(800));
Loading