Create a function (e.g nFib) that takes a single integer parameter, n, and returns a list of the first n elements of the Fibonacci sequence.
Example in Javascript:
const nFib = (n) => {
// TODDO solution begins here
return [];
};
// Leetcode Question | |
// https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/?envType=study-plan-v2&envId=top-interview-150 | |
/** | |
* @param {number[]} nums | |
* @return {number} | |
*/ | |
var removeDuplicates = function(nums) { | |
// ASC [1, 1, 1, 1, 1, 2, 2, 3, 4, 4, 5] | |
// index 0 1 2 3 4 5 6 7 8 9 10 |
Create a function (e.g nFib) that takes a single integer parameter, n, and returns a list of the first n elements of the Fibonacci sequence.
Example in Javascript:
const nFib = (n) => {
// TODDO solution begins here
return [];
};
-- Given the data at https://gist.github.com/chalu/da81ea79bc95292e5c892621b002fe8f | |
-- how would you calculate the average age of the seniors. | |
-- I use the following ChatGPT prompt to get the formula for calculating their average age | |
-- "Given some age ranges like 45 - 54 and the number of people in each age range, how would you calculate the average age across all the age ranges" | |
-- I then wrote the below SQL | |
WITH age_range AS ( | |
-- count seniors within each age range | |
SELECT SUM( |
Gender | Nursing Home | City Quadrant | Age 45-54 | Age 55-64 | Age 65-74 | Age 75+ | |
---|---|---|---|---|---|---|---|
Female | Maple Gardens | North | 12 | 18 | 25 | 35 | |
Male | Maple Gardens | North | 15 | 20 | 30 | 45 | |
Female | Sunflower Manor | South | 10 | 15 | 20 | 25 | |
Male | Sunflower Manor | South | 12 | 18 | 25 | 30 | |
Female | Rosewood Haven | East | 8 | 12 | 18 | 30 | |
Male | Rosewood Haven | East | 10 | 14 | 22 | 35 | |
Female | Oakridge Lodge | West | 18 | 25 | 35 | 50 | |
Male | Oakridge Lodge | West | 20 | 30 | 40 | 55 | |
Female | Aspen Meadows | North | 12 | 18 | 30 | 40 |
'use strict'; | |
const fs = require('file-system'); | |
const minimatch = require('minimatch'); | |
const path = require('path'); | |
const DEFAULT_CONFIG = { | |
'staticPath': [ 'static' ], | |
'watcherGlob': null | |
}; |
/* The API | |
================== */ | |
const noop = () => { }; | |
// abstract matcher | |
const match = (field = '', delegate = noop) => { | |
return (data = []) => { | |
return data.filter(entry => delegate(entry[field])); | |
} |
const getElligibleCustomers = chain( | |
customerAgeIsOrAbove(18), | |
isCustomerForMoreThan3Years, | |
totalItemsBoughtIsOver(50), | |
shippingAddressIsWithin(['Abuja', 'Lagos', 'Ibadan']) | |
); | |
const determineDiscountSale = chain( | |
getElligibleCustomers, | |
discountOrdersAt('15%'), |
const chain = (...fns) => { | |
return (data) => { | |
return fns.reduce((computed, fn) => { | |
return fn(computed); | |
}, data); | |
}; | |
}; | |
// use as | |
// chain(steps)(initialData) |
const is = (target) => (value) => value === target; | |
const isOver = (target) => (value) => value > target; | |
const isUnder = (target) => (value) => value < target; | |
const isOrOver = (target) => (value) => value >= target; | |
const isOrUnder = (target) => (value) => value <= target; | |
const isMultipleOf = (target) => (value) => value % target === 0; | |
// thus, easy to make isEven, isOdd, isPrime, isEnabled, isConnected, isStared | |
// isFavorite, is404, isImageResponse e.t.c |
const match = (field, delegate) => { | |
return (data = []) => { | |
return data.filter(entry => delegate(entry[field])); | |
} | |
}; |