Skip to content

Instantly share code, notes, and snippets.

View brainyfarm's full-sized avatar

Olawale Akinseye brainyfarm

View GitHub Profile
@brainyfarm
brainyfarm / merge_sort.js
Created February 14, 2019 12:26
My Mergesort implementation
// O(nlogn)
// Merge two sorted arrays
const merge = (arr1, arr2) => {
const sorted = [];
let i = 0;
let j = 0;
// Loop through both arrays and push the greater elements by
while(i < arr1.length && j < arr2.length) {
if(arr2[j] > arr1[i]) {
@brainyfarm
brainyfarm / insertion_sort.js
Created February 13, 2019 19:01
Insertion sort
/**
* Insertion sort.
* O(n^2)
*/
const insertionSort = (arr) => {
for(let i = 1; i < arr.length; i++) {
let j = i;
// const prev = arr[j-1];
// const next = arr[j];
// console.log(prev, next)
@brainyfarm
brainyfarm / bubble_sort.js
Last active February 7, 2019 11:44
Bubble Sort JS
/**
* My JS Implementation of Bubble Sort.
*/
const bubbleSort = arr => {
let noSwaps;
/**
* Swap element in an arr for another
*/
const swap = (arr, index1, index2) => {
@brainyfarm
brainyfarm / bootstrap-list-grid-view.markdown
Created January 29, 2018 08:13
Bootstrap List Grid View
@brainyfarm
brainyfarm / index.html
Created January 18, 2018 15:51
React First Code
<div id="app"></div>
@brainyfarm
brainyfarm / caesars_cipher.py
Created August 8, 2016 16:05
FreeCodeCamp: Caesar's Cipher (Python)
# -*- coding: utf-8 -*-
"""
One of the simplest and most widely known ciphers is a Caesar cipher, also known as a shift cipher.
In a shift cipher the meanings of the letters are shifted by some set amount.
A common modern use is the ROT13 cipher, where the values of the letters are shifted by 13 places.
Thus 'A''N', 'B''O' and so on.
Write a function which takes a ROT13 encoded string as input and returns a decoded string.
@brainyfarm
brainyfarm / where_belong.py
Created August 8, 2016 14:50
FreeCodeCamp: Where do I Belong (Python)
"""
Return the lowest index at which a value (second argument)
should be inserted into an array (first argument) once it has been sorted.
The returned value should be a number.
For example, getIndexToIns([1,2,3,4], 1.5) should return 1
because it is greater than 1 (index 0), but less than 2 (index 1).
Likewise, getIndexToIns([20,3,5], 19) should return 2
because once the array has been sorted it will look like [3,5,20]
@brainyfarm
brainyfarm / seek_and_destroy.py
Created August 8, 2016 14:31
FreeCodeCamp: Seek and Destroy (Python)
"""
You will be provided with an initial array (the first argument),
followed by one or more arguments.
Remove all elements from the initial array that are of the same value as these arguments.
"""
def destroyer(*args):
the_list = args[0]
to_remove = list(args[1:])
# Doing some list comprehension
return [element for element in the_list if element not in to_remove]
@brainyfarm
brainyfarm / falsy_bouncer.py
Last active August 8, 2016 10:44
FreeCodeCamp: Falsy Bouncer (Python)
"""
null in js, None in python
false is False
Remove all falsy values from an array.
Falsy values in JavaScript are false, null, 0, "", undefined, and NaN
I had to modify some stuff from this challenge due to some differences
in Javascript and Python
"""
@brainyfarm
brainyfarm / mutation.py
Created August 8, 2016 10:00
FreeCodeCamp: Mutations (Python)
"""
Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.
For example, ["hello", "Hello"], should return true because all of the letters in the second string are present in the first, ignoring case.
The arguments ["hello", "hey"] should return false because the string "hello" does not contain a "y".
Lastly, ["Alien", "line"], should return true because all of the letters in "line" are present in "Alien".
"""
def mutation(the_list):