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
16 changes: 16 additions & 0 deletions codewars/Adding Big Numbers/Adding Big Numbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function add(a, b) {
let result = '';
let carry = 0;
let i = a.length - 1;
let j = b.length - 1;
while (i >= 0 || j >= 0 || carry > 0) {
const digit1 = i >= 0 ? parseInt(a[i], 10) : 0;
const digit2 = j >= 0 ? parseInt(b[j], 10) : 0;
const sum = digit1 + digit2 + carry;
carry = Math.floor(sum / 10);
result += (sum % 10).toString();
i--;
j--;
}
return result.split('').reverse().join('');
}
15 changes: 15 additions & 0 deletions codewars/Anagram difference/Anagram Differnce.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function anagramDifference(w1, w2) {
let k = 0;
let freq = {};
for (let i = 0; i < w1.length; i++) {
freq[w1[i]] = (freq[w1[i]] || 0) + 1;
}
for (let i = 0; i < w2.length; i++) {
freq[w2[i]] = (freq[w2[i]] || 0) - 1;
}
for (let letter in freq) {
k += Math.abs(freq[letter]);
}

return k
}
13 changes: 13 additions & 0 deletions codewars/Array Deep Count/Array Deep Count.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function deepCount(a){
let result = 0
const recursion = arr => {
result += arr.length
for (let i of arr) {
if (Array.isArray(i) ) {
recursion(i);
}
}
}
recursion(a)
return result
}
11 changes: 11 additions & 0 deletions codewars/Build Tower/Build Tower.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function towerBuilder(nFloors) {
let voids = [];
let bricks = [];
let tower = [];
for (i = 1; i <= nFloors; i++) {
voids = ' '.repeat(nFloors - i);
bricks = '*'.repeat((2*i) - 1);
tower.push(`${voids}${bricks}${voids}`);
}
return tower;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function toCamelCase(str){
let words = str.replaceAll('_','-').split('-')
let result = []
result.push(words[0])
for (i=1;i<words.length;i++){
let word = words[i].toString()
word=word[0].toUpperCase()+word.slice(1)
result.push(word)
}
return result.join('')
}
12 changes: 12 additions & 0 deletions codewars/Duplicate Encoder/Duplicate Encoder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function duplicateEncode(word){
var counter = {};
var letters = word.toLowerCase().split('');

letters.forEach(function(letter) {
counter[letter] = (counter[letter] || 0) + 1;
});

return letters.map(function(letter) {
return counter[letter] === 1 ? '(' : ')';
}).join('');
}
8 changes: 8 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,8 @@
function findMissingLetter(array){
var string = array.join('')
for (i=0;i<string.length;i++){
if (string.charCodeAt(i+1)-string.charCodeAt(i)!=1){
return String.fromCharCode(string.charCodeAt(i)+1)
}
}
}
13 changes: 13 additions & 0 deletions codewars/Flatten a Nested Map/Flatten a Nested Map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function flattenMap(object) {
function iter(part, keys) {
Object.keys(part).forEach(function (k) {
if (part[k] !== null && !Array.isArray(part[k]) && typeof part[k] === 'object') {
return iter(part[k], keys.concat(k));
}
flat[keys.concat(k).join('/')] = part[k];
});
}
var flat = {};
iter(object, []);
return flat;
}
17 changes: 17 additions & 0 deletions codewars/Fun with tree - max sum/Fun with tree - max sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function maxSum(root) {
let left = -Infinity
let right = -Infinity
if (root === null){
return 0
}
if (root.left === null && root.right === null ){
return root.value
}
if (root.left){
left = maxSum(root.left)
}
if (root.right){
right = maxSum(root.right)
}
return root.value+Math.max(left,right)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function Node(data) {
this.data = data;
this.next = null;
}

function sortedInsert(head, data) {
const newNode = new Node(data);
if (!head) {
return newNode;
}
if (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;
}
18 changes: 18 additions & 0 deletions codewars/Merge two arrays/Merge Two Arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function mergeArrays(a, b) {
let result=[]
min = a.length > b.length ? b.length : a.length;
for (let i=0;i<min;i++){
result.push(a[i])
result.push(b[i])
}
if (a.length>b.length){
for (let j = min;j<a.length;j++){
result.push(a[j])
}
} else {
for (let j = min;j<b.length;j++){
result.push(b[j])
}
}
return result
}
15 changes: 15 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,15 @@
function moveZeros(arr) {
let result = []
let count = 0
for (i=0;i<arr.length;i++){
if (arr[i]!==0){
result.push(arr[i])
} else {
count++
}
}
for (j=0;j<count;j++){
result.push(0)
}
return result
}
22 changes: 22 additions & 0 deletions codewars/Permutations/Permutations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function permutations(str) {
if (str.length === 0) {
return [];
}
if (str.length === 1) {
return [str];
}
const uniquePerm = new Set();
function genPerm(cur, remain) {
if (remain.length === 0) {
uniquePerm.add(cur);
return;
}
for (let i = 0; i < remain.length; i++) {
const newCur = cur + remain[i];
const newRemain = remain.slice(0, i) + remain.slice(i + 1);
genPerm(newCur, newRemain);
}
}
genPerm("", str);
return Array.from(uniquePerm);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function productFib(prod){
let fib = [0,1,1]
while ((fib[fib.length-1]*fib[fib.length-2])<prod){
fib.push((fib[fib.length-2]+fib[fib.length-1]))
}
if ((fib[fib.length-1]*fib[fib.length-2])===prod){
return [fib[fib.length-2],fib[fib.length-1],true]
} else {
return [fib[fib.length-2],fib[fib.length-1],false]
}
}
14 changes: 14 additions & 0 deletions codewars/Simple Pig Latin/Simple Pig Latin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function pigIt(str){
let camel = str.split(' ')
let result = []
for (i=0;i<camel.length;i++){
if (camel[i]==='!' || camel[i]==='?'){
result.push(camel[i])
} else {
let word = camel[i].split('')
word.push(word.shift(),'ay')
result.push(word.join(''))
}
}
return result.join(' ')
}
33 changes: 33 additions & 0 deletions codewars/Snail/Snail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function snail(matrix) {
if (matrix.length === 0) return [];
const result = [];
const rows = matrix.length;
const cols = matrix[0].length;
let top = 0, bottom = rows - 1;
let left = 0, right = cols - 1;

while (top <= bottom && left <= right) {
for (let i = left; i <= right; i++) {
result.push(matrix[top][i]);
}
top++;
for (let i = top; i <= bottom; i++) {
result.push(matrix[i][right]);
}
right--;
if (top <= bottom) {
for (let i = right; i >= left; i--) {
result.push(matrix[bottom][i]);
}
bottom--;
}

if (left <= right) {
for (let i = bottom; i >= top; i--) {
result.push(matrix[i][left]);
}
left++;
}
}
return result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function digitalRoot(n) {
if (n.toString().length == 1) {
return n
}
let arr = n.toString().split('')
let result = 0
for (i=0;i<arr.length;i++){
arr[i] = +arr[i] | 0
result += arr[i]
}
return digitalRoot(result)

}
21 changes: 21 additions & 0 deletions codewars/Sum of Intervals/Sum of Intervals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function sumIntervals(intervals) {
intervals.sort((a, b) => a[0] - b[0]);
let ans = 0;
let intervalsListed = intervals.map(x => [...x]);
let intervalsTwo = [intervalsListed[0]];

for (let cur of intervalsListed) {
let prev = intervalsTwo[intervalsTwo.length - 1];
if (cur[0] <= prev[1]) {
prev[1] = Math.max(prev[1], cur[1]);
} else {
intervalsTwo.push(cur);
}
}

for (let i of intervalsTwo) {
ans += i[1] - i[0];
}

return ans;
}
12 changes: 12 additions & 0 deletions codewars/Sum of pairs/Sum of Pairs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function sumPairs(ints, s) {
const seen = {};
for (let i = 0; i < ints.length; i++) {
const currentNum = ints[i];
const complement = s - currentNum;
if (seen[complement] !== undefined) {
return [complement, currentNum];
}
seen[currentNum] = i;
}
return undefined;
}
24 changes: 24 additions & 0 deletions codewars/Tic-Tac-Toe Checker/Tic-Tac-Toe Cheker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function isSolved(board) {
for (let i = 0; i < 3; i++) {
if (board[i][0] === board[i][1] && board[i][1] === board[i][2] && board[i][0] !== 0) {
return board[i][0];
}
if (board[0][i] === board[1][i] && board[1][i] === board[2][i] && board[0][i] !== 0) {
return board[0][i];
}
}
if (board[0][0] === board[1][1] && board[1][1] === board[2][2] && board[0][0] !== 0) {
return board[0][0];
}
if (board[0][2] === board[1][1] && board[1][1] === board[2][0] && board[0][2] !== 0) {
return board[0][2];
}
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
if (board[i][j] === 0) {
return -1;
}
}
}
return 0;
}
18 changes: 18 additions & 0 deletions codewars/Valid Parentheses/Valid Parentheses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function validParentheses(s) {
const stack = [];
const parenthesesMap = { ')' : '(' }

for (let i = 0; i < s.length; i++) {
const char = s[i];

if (char === '(') {
stack.push(char);
} else if (char === ')') {
if (stack.length === 0 || stack.pop() !== parenthesesMap[char]) {
return false;
}
}
}

return stack.length == 0;
}
3 changes: 3 additions & 0 deletions codewars/Where my anagrams at/Where my anagrams at.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function anagrams(word, words) {
return words.filter(w => w.split('').sort().join('') === word.split('').sort().join(''));
}
6 changes: 5 additions & 1 deletion onlineshop/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ NODE_ENV=development
SERVER_HOST=localhost
SERVER_PORT=3000
SERVER_WEB_HOST=localhost
SERVER_WEB_PORT=4000
SERVER_WEB_PORT=4000
DB_USER=postgres
DB_PASSWORD=postgres
DB_PORT=5432
DB_NAME=sample
Loading