Flatten nested arrays of integers

Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers.

example:

flatten([[1, 2, [3]], 4]);
// [1, 2, 3, 4]

Read More

Share Comments

Merging 2 packages

Given a package with a weight limit and an array of item weights, how can you most efficiently find two items with sum of weights that equals the weight limit?

Your function should return 2 such indices of item weights or -1 if such pair doesn’t exist. What is the runtime and space complexity of your solution?

example:

findComplementingWeights([2, 4, 8, 14], 12);
// [1, 2] or [2, 1]

Read More

Share Comments

String reverse

Write a function to return a reversed string for given string

example:

reverse('you are a nice dude');
// "edud ecin a era uoy"

Read More

Share Comments

Swap number without temp

Write a function to swap two numbers without an additional variable

example:

swapNumb(2, 3);
// before swap: a:2 b:3
// after swap: a:3 b:2

Read More

Share Comments

Find point

Given two points P and Q, output the symmetric point of point P about Q

Find point

Read More

Share Comments

Merge two sorted arrays

Write a function to return an array that two arrays are merged in

example:

mergeSortedArray([2, 5, 6, 9], [1, 2, 3, 29]);
// [1, 2, 2, 3, 5, 6, 9, 29]

Read More

Share Comments

Remove Duplicate

Write a function to return an array that duplicate primitive values are removed in

example:

removeDuplicate([1, 3, 3, 3, 1, 5, 6, 7, 8, 1]);
// [1, 3, 5, 6, 7, 8]

Read More

Share Comments

Greatest Common Divisor

Write a function to return GCD(Greatest Common Divisor) of two numbers

example:

greatestCommonDivisor(14, 21);
// 7;
greatestCommonDivisor(69, 169);
// 1;

Read More

Share Comments

Fibonacci Number

Write a function to return the nth Fibonacci number

example:

fibonacci(0);
// 1
fibonacci(1);
// 1
fibonacci(2);
// 2
fibonacci(3);
// 3
fibonacci(4);
// 5
//
// 1, 1, 2, 3, 5, 8, 13, 21, ···

Read More

Share Comments

Prime factors

Write a function to return an array for prime factors of a number

example:

primeFactors(69);
// [3, 23]

Read More

Share Comments