Skip to content

Instantly share code, notes, and snippets.

View petercr's full-sized avatar
😎
Probably pushing some JS code

Peter Cruckshank petercr

😎
Probably pushing some JS code
View GitHub Profile
@petercr
petercr / ceasar.js
Created April 24, 2022 21:55
My Solution to Caesar's Cipher in TypeScript: I had to set to JS to get syntax highlighting
function caesarCipher(phraze: string, offBy: number): string {
function hasLowerCase(str: string): boolean {
return /[a-z]/.test(str);
}
function hasUpperCase(str: string): boolean {
return /[A-Z]/.test(str);
}
// Here's that alphabet string
const aToZ = "abcdefghijklmnopqrstuvwxyz";
const uppercaseAtoZ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@petercr
petercr / pangram.js
Created February 28, 2022 21:27
A function that takes in a String (in EN) and returns whether or not it is a pangram. Has all the letters of the alphabet in it.
function pangrams(s) {
// String to hold EN alphabet
const alphabet = "abcdefghijklmnopqrstuvwxyz";
// Regex to remove all white spaces
const removeSpaces = /\s/g;
// take String s and change to lowercase
s = s.toLowerCase().replace(removeSpaces, "");
// Loop over the alphabet and check for each letter
for (let index = 0; index < alphabet.length; index++) {
@petercr
petercr / countingSort.js
Created February 25, 2022 19:14
Solution to the Hackerrank Algorithm for Couting Sort 1
function countingSort(arr) {
// Create new Array to hold sorted values
const results = new Array(10).fill(0);
// Loop through array and add values to results array
for (let i = 0; i < arr.length; i++) {
const currentNum = parseInt(arr[i], 10);
if (typeof results[i] === undefined) {
results[i] = 0;
}
@petercr
petercr / diagonalDiff.js
Created February 23, 2022 23:18
A JavaScript function takes in a 2D array and adds the diagonal values each way. It then compares the absolute value of both.
/*
* Complete the 'diagonalDifference' function below.
*
* The function is expected to return an INTEGER.
* The function accepts 2D_INTEGER_ARRAY arr as parameter.
*
*/
function diagonalDifference(arr) {
// Loop over the array both ways
@petercr
petercr / lonelyInt.js
Created February 22, 2022 01:33
My Solution To The Lonely Interger Problem in JavaScript
/*
* Complete the 'lonelyinteger' function below.
*
* The function is expected to return an INTEGER.
* The function accepts INTEGER_ARRAY a as parameter.
*/
function lonelyinteger(a) {
// If a is only 1 int long just return it
if(a.length == 1) {
@petercr
petercr / timeFormat.js
Created February 9, 2022 02:10
The code I used to solve the Time Conversion algorithm on HackerRank
function timeConversion(s) {
// Take the time passed in and check for AM | PM
// If the time is AM, then just remove the AM unless it's 12
if (s.endsWith("AM")) {
// add the first 2 numbers from s to firstNumSet
let firstNumSet = parseInt(s.substring(0,2));
// if first number is 12, make it 00
if (firstNumSet === 12) {
firstNumSet = "00";
@petercr
petercr / example.css
Created August 8, 2021 01:13
A CSS Prefers Reduced Motion Media Query
.fun-animation {
animation: 3s linear 1s infinite running slidein;
}
/* Here's where we turn the animation off */
@media (prefers-reduced-motion) {
.fun-animation {
animation-name: none;
}
}
@petercr
petercr / sample_spec.js
Created September 9, 2020 01:13
Here's the code from my first Cypress test! 🥳
describe(`My First Test`, function () {
it(`Is doing something...?`, function () {
expect(true).to.equal(true)
})
})