Skip to content

Instantly share code, notes, and snippets.

View prismhead26's full-sized avatar

Aiden Wahed prismhead26

View GitHub Profile
@prismhead26
prismhead26 / regEx.md
Last active April 21, 2024 07:00
RexEg Tutorial & Cheetsheet

Regular Expressions Tutorial

The purpose of this gist is to create a helpful walkthrough explaining the ins and outs of regular expressions. Regular expressions, or regex for short, are a series of special characters that define a search pattern. Essentially, a regular expression can be used to match a certain RexEx pattern against a string. This is very useful for pulling data and validating the results. This tutorial will follow the example below that can be used to match against an email address.

Summary

In this tutorial, I will break down the regular expression below that helps validate for a particular pattern; in this case, we will be validating an email address. This is useful because it looks for an email that matches the correct format via RegEx.

Matching Email-

@prismhead26
prismhead26 / concert-flyer.js
Created April 19, 2024 17:15
Concert Flyer Javascript challenge
// Write a function that takes two strings and returns true if every word found in the second string is present in the
// first string. You will be checking for both words and their frequency. Assume you'll need to worry about casing,
// but the strings won't contain any punctuation. Assume neither string will be empty
var concertFlyer = function (magazine, flyer) {
const arr = flyer.split(' ')
let boolean = []
arr.forEach(word => {
if(magazine.indexOf(word) === -1) {
boolean.push(false)
@prismhead26
prismhead26 / simple-mock-interview.js
Created April 19, 2024 17:10
Front end Interview challenges
/**
Youtube Interview Link:
https://www.youtube.com/watch?v=vomuCMmoNyE&t=2628s
Write a function that takes two numbers and returns
the sum of those numbers
*/
function add(num1, num2) {
let sum = num1 + num2
@prismhead26
prismhead26 / fizzbuzz.js
Created April 19, 2024 17:09
Classic fizzbuzz
function fizzBuzz(num) {
let output = [];
for (let i = 1; i <= num; i++) {
if (i % 3 === 0 && i % 5 === 0) {
output.push('FizzBuzz');
} else if (i % 3 === 0) {
output.push('Fizz');
} else if (i % 5 === 0) {
output.push('Buzz');
@prismhead26
prismhead26 / createCounter.js
Created April 19, 2024 17:08
Counter algorithm in Javascript
/* Write a function (createCounter). It should accept an intitial integer (init).
It should return an object with three functions.
The three functions are:
-- increment() increases the current value by 1 and then returns it
-- decrement() reduces the current value by 1 and then returns it
-- reset() sets the current value to (init) and then returns it.
*/
const createCounter = function(init) {
@prismhead26
prismhead26 / phone-num-regex.js
Created April 19, 2024 06:51
Phone Number Regular Expression
const phoneRegEx = /(?:(?<international>\+1)[ -])?\(?(?<areacode>\d{3})\)?[ -]?(?<prefix>\d{3})[ -]?(?<line_number>\d{4})/
// 1234567890
// 123-456-7890
// 123 456 7890
// (123) 456 7890
// +1 123 456 7890
@prismhead26
prismhead26 / interview-questions.js
Created April 19, 2024 06:36
Top 5 Interview Questions
/* Top 5 most popular
5: What is the difference between GET and POST when making an AJAX request?
GET and POST are two different HTTP requests
Use GET when retrieving data from the server
Use POST when sending data from the client to the server to create/update a resource
@prismhead26
prismhead26 / max-char.js
Created April 19, 2024 06:34
Maximum Characters Javascript
const str = 'abbccccddd';
function maxChar(str) {
let charMap = {};
let max = 0;
let char = '';
for (char of str) {
charMap[char] = ++charMap[char] || 1
@prismhead26
prismhead26 / array-chunks.js
Created April 19, 2024 06:33
Array Chunks Javascript
function chunk(array, size) {
return array.reduce((acc, val, i) => {
if (i % size === 0) {
acc.push([]);
console.log(acc);
console.log(i);
}
console.log(val);
acc[acc.length - 1].push(val);
return acc;
@prismhead26
prismhead26 / anagram.js
Created April 19, 2024 06:32
Anagram Javascript
const str = 'coding money';
const str2 = 'money coding';
const str3 = 'RAIL! SAFETY!';
const str4 = 'fairy tales';
function anagram(str1, str2) {
const str1Arr = str1.toLowerCase().replace(/[\W]/g,'').split('').sort();
console.log(str1Arr);
const str2Arr = str2.toLowerCase().replace(/[\W]/g,'').split('').sort();