Skip to content

Instantly share code, notes, and snippets.

View torressam333's full-sized avatar
📖
Proverbs 3:5

Samuel Torres torressam333

📖
Proverbs 3:5
View GitHub Profile
@torressam333
torressam333 / App.css
Created January 24, 2024 01:58
React Portal Example Implementation
.alert {
position: relative;
top: 10px;
left: 50%;
translate: -50%;
background-color: aquamarine;
color: black;
border-radius: 5px;
padding: 10px;
cursor: pointer;
@torressam333
torressam333 / HOCWithConfig.jsx
Created January 8, 2024 17:37
Higher Order Component with Configuration Example in React
/**
* This way, configuring a Higher-Order Component is essentially just the addition of another wrapping function around it.
* We accept custom messages for loading, no data or empty from the Wrapped Component
* OR, we provide default/generic fallback states if wrapped component doesn't provide them.
* @param {*} dataEmptyFeedback
* @param {*} noDataFeedback
* @param {*} dataEmptyFeedback
* @returns
*/
const withConditionalFeedback =
@torressam333
torressam333 / sameFrequency.js
Created December 16, 2022 17:34
Solved same frequency challenge using JavsScript
/**
* Write a function called sameFrequency. Given two positive integers, find out if the two numbers have the same frequency of digits.
The solution MUST have the following complexities:
Time: O(N)
Sample Input:
sameFrequency(182,281) // true
@torressam333
torressam333 / maxSubArraySum.js
Created December 15, 2022 22:29
Solves the max sub array sum with O(n) time complexity using JavaScript.
/**
* Write a function which accepts an array of integers
* and a number called n.
*
* The function should calculate the maximum sum of n consecutive
* elements in the array.
*/
const maxSubArraySum = (arr, n) => {
if (!arr.length) return null;
@torressam333
torressam333 / CountUniqueValues.js
Created December 13, 2022 01:02
Gist demonstrating 3 different O(n) Methods For Getting Unique Values Count in JavaScript
/**
* Count Unique Values Problem solved 3 ways
*
* Prompt: Implement a function which accepts a sorted array and counts
* the unique values in the array.
*
* Negative numbers are allowed and will only be numbers.
* The array is always sorted*
*
* @param {*} sortedArr
@torressam333
torressam333 / validAnagram.js
Created December 8, 2022 21:39
Valid Anagram Challenge - Accounts for Whitespaces, special chars and letter casing
const validAnagram = (str1, str2) => {
// convert to lowercase and remove spaces
str1 = str1.replace(/\s+/g, "").toLowerCase();
str2 = str2.replace(/\s+/g, "").toLowerCase();
// Check for length once whitespace is removed
if (str1.length !== str2.length) return false;
// Only nums and lowercase letters allowed
const regex = /^[\w.-]+$/;
@torressam333
torressam333 / SimpleValidAnagram.js
Created December 8, 2022 20:51
Simple Version of Valid Anagram O(n) Time Complexity
/* Simple b/c it doesn't account for spaces, special chars etc...*/
const validAnagram = (str1, str2) => {
// Immediately return if strings are diff length
if (str1.length !== str2.length) return false;
// Create "bank" for letters to live in
let chars = {};
// Loop over first string and add letters to chars
@torressam333
torressam333 / CreditCardStringParseAndValidateExpiration.js
Last active October 1, 2022 20:43
Parse a credit card date string into a date object and determine if it is expired - JavaScript
/**
Takes in the expirationDate param as: "3/2025" or "03/2025" etc...
Rookie Implementation
**/
export default function isCreditCardExpired(expirtationDate) {
const now = new Date();
const currentMonth = now.getMonth() + 1; // 9
const currentYear = now.getFullYear(); // 2022
@torressam333
torressam333 / timeConversion.php
Last active February 27, 2020 14:38
Hackerrank Time Conversion Solution
<?php
//Convert standard 12 hour time to 24 hour "Military Time" using php
//use the PHP date functiont to format the date
//use PHP strtotime to convert the time to the specified format
function timeConversion($s) {
/*
* Write your code here.
*/
@torressam333
torressam333 / birthdayCakeCandles.php
Created February 26, 2020 18:57
Hackerrank Birthday Cake Candles
<?php
// Complete the birthdayCakeCandles function below.
function birthdayCakeCandles($ar) {
//Count occurrance of each value in array
$candleCount = array_count_values($ar);
//This is the single higest value in the array
$tallestCandleCount = max($candleCount);