Skip to content

Instantly share code, notes, and snippets.

View trunkslamchest's full-sized avatar

Austin Smith trunkslamchest

View GitHub Profile
@trunkslamchest
trunkslamchest / fetchFunctions.js
Last active September 8, 2021 17:59
IIFC to send basic GET/POST HTTP requests
// SUMMARY:
// This Immidiately Invoked Function Constructor is designed to abstract/boilerplate basic JS GET/POST requests,
// specifically with React & Redux.
//
// I wrote a 7 part blog series detailing how this file works:
// - https://levelup.gitconnected.com/function-construction-whats-your-function-5a282b81fc62
//
// USAGE:
// - import this file into your component:
// - import fetchFunctions from <your path to the file>
@trunkslamchest
trunkslamchest / blog30_solution_final.js
Last active August 30, 2020 18:23
blog30_solution_final.js
var minSubsequence = function(nums) {
let sum = nums.reduce((a, b) => a + b ), subSum = 0, sub = []
nums.sort((a, b) => a - b)
for(i = nums.length - 1; i >= 0; i--){
if(sum >= subSum) {
subSum += nums[i]
sum = sum - nums[i]
sub.push(nums[i])
} else break
@trunkslamchest
trunkslamchest / blog30_solution6.js
Last active August 30, 2020 18:23
blog30_solution6.js
var minSubsequence = function(nums) {
let sum = nums.reduce((a, b) => a + b )
let subSum = 0
let sub = []
nums.sort((a, b) => a - b)
for(i = nums.length - 1; i >= 0; i--){
if(sum >= subSum) {
subSum += nums[i]
@trunkslamchest
trunkslamchest / blog30_solution5.js
Last active August 30, 2020 18:23
blog30_solution5.js
var minSubsequence = function(nums) {
let sum = nums.reduce((a, b) => a + b )
let subSum = 0
let sub = []
nums.sort((a, b) => a - b)
for(i = nums.length - 1; i >= 0; i--){
if(sum >= subSum) {
@trunkslamchest
trunkslamchest / blog30_solution4.js
Created August 30, 2020 17:40
blog30_solution4.js
var minSubsequence = function(nums) {
let sum = nums.reduce((a, b) => a + b )
let subSum = 0
let sub = []
nums.sort((a, b) => a - b)
for(i = nums.length - 1; i >= 0; i--){
// if sum is greater than or equal to subSum
@trunkslamchest
trunkslamchest / blog30_solution3.js
Created August 30, 2020 17:38
blog30_solution3.js
var minSubsequence = function(nums) {
let sum = nums.reduce((a, b) => a + b )
let subSum = 0
let sub = []
nums.sort((a, b) => a - b)
// iterate through nums (which is now sorted) backwards
for(i = nums.length - 1; i >= 0; i--){
@trunkslamchest
trunkslamchest / blog30_solution2.js
Created August 30, 2020 17:36
blog30_solution2.js
var minSubsequence = function(nums) {
let sum = nums.reduce((a, b) => a + b )
let subSum = 0
let sub = []
// sort nums from least to greatest
nums.sort((a, b) => a - b)
};
@trunkslamchest
trunkslamchest / blog30_solution1.js
Created August 30, 2020 17:35
blog30_solution1.js
var minSubsequence = function(nums) {
// sum: an integer. the total sum of nums without any mutations
let sum = nums.reduce((a, b) => a + b )
// the total sum of the subsequence we are building
let subSum = 0
// the subsequence we want to build, then return at the end of the solution
let sub = []
@trunkslamchest
trunkslamchest / blog30_pseudo
Last active August 30, 2020 18:22
blog30_pseudo
// - create 3 variables:
// - sum: an integer. the total sum of nums without any mutations
// - subSum: an integer. the total sum of the subsequence we are building
// - sub: an empty array. the subsequence we want to build, then return at the end of the solution
// - since we need to return a subsequence with the maximum total sum of all its elements
// - sort nums from least to greatest and iterate from the last element to the first
// - this will allow us to add each element of num so that every sum of the subsequence will be the maximum possible sum of a subsequence
// - this will also allow us to build the subsequence in non-increasing order
// since the last number in nums will always be the largest number in nums,
@trunkslamchest
trunkslamchest / blog30_tests
Created August 30, 2020 15:57
blog30_tests
Test Case #1:
Input: nums = [4,3,10,9,8]
Output: [10,9]
Explanation: The subsequences [10,9] and [10,8] are minimal
such that the sum of their elements is strictly greater than the sum of elements not included, however,
the subsequence [10,9] has the maximum total sum of its elements.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~