Skip to content

Instantly share code, notes, and snippets.

@james-prado
james-prado / quicksort.js
Last active January 25, 2017 18:47
QuickSort Recursive Function In JavasScript
function quickSort(numbers, target, partial) {
var sum, remaining;
var partial = partial || [];
// sum partial
sum = partial.reduce(function (a, b) {
return a + b;
}, 0);
// check if the sum partial equals the target
@james-prado
james-prado / main.py
Created April 24, 2017 21:27
Project Euler Question 1
# If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
# Find the sum of all the multiples of 3 or 5 below 1000.
class Multiples:
def __init__(self, num, min, max):
self.__num = num
self.__min = self.round_step(min)
self.__max = max
@james-prado
james-prado / main.py
Created April 25, 2017 05:48
Project Euler Question 2
# Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
#
# 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
#
# By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
# Find the sum of the even-valued terms < four million in the Fibonacci sequence
class Fibonacci_numbers:
@james-prado
james-prado / deep_flatten.js
Last active September 5, 2018 14:07
Deep flatten an array
const input = [[1, 2, [3]], 4];
// ––––– Option 1 –––––
function baseFlatten(array, depth, result) {
result || (result = []);
if (array == null) {
return result;
}