Skip to content

Instantly share code, notes, and snippets.

View chalu's full-sized avatar

Charles Opute Odili chalu

View GitHub Profile
@chalu
chalu / js-BST
Last active March 1, 2017 11:14
1st Attempt - JavaScript Binary Search (Done in Lagos Traffic!)
let binarySearch = (haystack, needle) => {
let allNums = haystack.every( entry => !isNaN(entry) );
let needleIsNum = !isNaN(needle);
if( needleIsNum && allNums){
// prepare inputs
haystack = haystack.sort( (a, b) => a - b );
// define Algol
let bSearchr = (aHaystack) => {
@chalu
chalu / express-api-with-dummy-data
Last active September 28, 2017 12:44
Sample use of dummy in-memory data with an Express API endpoint
// Generate similar data from https://www.generatedata.com/
const dummyData = {
developers: [
{
"id": "870D1B3F-9259-99A7-F18E-18CA40B3B284",
"name": "Heather Bullock",
"experience": 12,
"stack": "iOS"
},
@chalu
chalu / if-correct-recursion.js
Created February 19, 2018 11:13
A number of countdown implementations to review
const countdownA = (limit) => {
for(let i = limit; i >= 1; i--) {
console.log('Now @ ' + i);
}
};
const countdownB = (limit) => {
console.log('Now @ ' + limit);
if (limit === 1) return 1;
@chalu
chalu / calculator.js
Created February 23, 2019 15:11
Tree Shaking With Parcel Bundler
export const add = (x, y) => x + y;
export const minus = (x, y) => x - y;
export const divide = (x, y) => x / y;
export const multiply = (x, y) => x * y;
[{
name: 'Alpha Ndimurukundo',
age: 33,
gender: 'Male',
country: 'Rwanda',
company: 'Andela'
}, ...]
const computed = data.reduce((sum, {age = 0}, index) => {
const value = sum + age;
if(index === data.length-1) return value / data.length;
return value;
}, 0);
{
name: 'Alpha Ndimurukundo',
age: 33,
gender: 'Male',
country: 'Rwanda',
company: 'Andela'
}
const sumAges = compute(sumOf, 'age');
const sumOfAge = sumAges(data);
const avgAge = compute(averageOf, 'age');
const avgOfAges = avgAge(data);
const compute = (delegate, field) => {
return (data) => delegate(data, field);
};