Skip to content

Instantly share code, notes, and snippets.

View Mk-Etlinger's full-sized avatar

Mike Etlinger Mk-Etlinger

  • Grand Rapids
View GitHub Profile
When wanting to use composition for your components, how do you handle cases where you always need to map items
for things like Radio Group or Accordion Items?
For example: https://chakra-ui.com/docs/disclosure/accordion
<Accordion>
// How can I encapsulate this without losing composition? Is it even worth it?
// In the case where we need to have other developers use this composition, how do we ensure they use it correctly?
// Using TypeScript btw
@Mk-Etlinger
Mk-Etlinger / hr-pairSum-v3.js
Created February 13, 2020 20:56
Hacker Rank pairSum challenge
function pairSum(data, target) {
const pairMatches = {};
for(let i = 0; i < data.length; i++) {
const number = data[i];
const difference = (target - number);
if (pairMatches[number]) {
return true;
}
@Mk-Etlinger
Mk-Etlinger / hr-pairSum-v2.js
Last active February 12, 2020 22:16
Hacker Rank - pairSum v2
function pairSum(data, target) {
let sumMatchesTarget;
data.forEach((currentNumber, index) => {
if (sumMatchesTarget) { return; }
const dataFiltered = removeCurrentIndex(data, index);
sumMatchesTarget = dataFiltered.some(nextNumber => {
const sum = (currentNumber + nextNumber);
@Mk-Etlinger
Mk-Etlinger / hr-pairSum-v1.js
Last active February 13, 2020 18:14
pairSum Solution
/*
* Complete the 'pairSum' function below.
*
* The function is expected to return a BOOLEAN.
* The function accepts following parameters:
* 1. INTEGER_ARRAY array
* 2. INTEGER target
*/
function pairSum(array, target) {
for(let i = 0; i < array.length; i++) {
@Mk-Etlinger
Mk-Etlinger / README.md
Created June 7, 2019 15:11 — forked from benjaminbarbe/README.md
Nginx proxy to S3 with caching
@Mk-Etlinger
Mk-Etlinger / setup.php
Created November 20, 2018 17:49
From setup.php
add_action('init', function(){
session_set_cookie_params( 0 );
if(!session_id())
session_start();
}, 1);
class ExpressionEvaluator
def self.parse(string)
complex_exps = string.scan(/-\s\d+\s\d+/)
simple_exps = string.gsub(/-\s\d+\s\d+/, '')
complex_sum(complex_exps) + simple_sum(simple_exps)
end
def self.complex_sum(array)
array.reduce(0) { |sum, exp| sum + (exp.split[1].to_i - exp.split[2].to_i) }
end
class ExpressionEvaluator
def self.parse(string)
complex_exps = string.scan(/-\s\d+\s\d+/)
simple_exps = string.gsub(/-\s\d+\s\d+/, '')
complex_sum(complex_exps) + simple_sum(simple_exps)
end
end
def self.parse(string)
sum = 0
char_array = string.split
char_array.each_with_index do |char, i|
sum += char.to_i
next unless char == '-' && char_array[i + 2]
if char_array[i + 2].to_i == 0
char_array[i + 1] = char + char_array[i + 1]
else
char_array[i + 2] = char + char_array[i + 2]

Implement an Expression Evaluator Our goal is to write a program that is capable of evaluating simple mathematical expressions. An example expression could look like:

+ 1 2 This expression can be read as 1 + 2 and evaluates to 3. We've placed the operator (+) first in our syntax to simplify some things down the road. The + indicates that this is an operator expression, and is evaluated by summing the two following tokens, which in this case are both numbers.

The general rules are:

Expressions can be numbers or operator expressions (4 is an expression and so is - 3 1) Numbers evaluate to themselves (4 is 4)