Skip to content

Instantly share code, notes, and snippets.

View gtodd876's full-sized avatar
๐ŸŒŽ

Todd Matthews gtodd876

๐ŸŒŽ
  • CarMax
  • Richmond, VA
View GitHub Profile
{
"React Component - Export default function": {
"prefix": "rfcd",
"body": [
"export default function ${1:ComponentName}() {",
" return (",
" <>",
" $0",
" </>",
" );",
@gtodd876
gtodd876 / chunk
Created December 18, 2017 00:02
Given an array and chunk size, divide the array into many subarrays
const chunk = (array, size) => {
let result = [];
while (array.length > 0) {
result.push(array.splice(0, size));
}
return result;
};
@gtodd876
gtodd876 / reverseInt.js
Created December 16, 2017 13:46
reverse and return an integer
// 1st solution
function reverseInt(n) {
var str = n
.toString()
.split('')
.reverse()
.join('');
if (n < 0) return parseInt('-' + str);
if (n >= 0) return parseInt(str);
@gtodd876
gtodd876 / palidrome.js
Last active December 16, 2017 00:19
check to see if a string is a palidrome
// 1st solution
const palindrome = (str) => (str === str.split('').reverse().join(''));
//second solution - inefficient solution - 2x the work
const palindrome = (str) => {
return str.split('').every( (char, index) => {
return char === str[str.length - i - 1];
}
}
@gtodd876
gtodd876 / reverseString
Last active December 15, 2017 16:01
different ways to reverse a string
//1st try
function reverse(str) {
var newStr = [];
for (var i = str.length - 1; i >= 0; i--) {
newStr.push(str[i]);
}
return newStr.join('');
}
//2nd attempt - 1 liner
@gtodd876
gtodd876 / fizzbuzz.js
Last active December 17, 2017 22:55
1st solution i tried for fizzbuzz
for (var i = 1; i <= 100; i++) {
if (i % 3 === 0 && i % 5 === 0) {
console.log('fizzbuzz');
} else if (i % 5 === 0) {
console.log('buzz');
} else if (i % 3 === 0) {
console.log('fizz');
} else {
console.log(i);
}
@gtodd876
gtodd876 / factorialize.js
Created October 10, 2017 16:05
Factorials
function factorialize(num) {
if (num < 2) return 1;
return num * factorialize(num-1);
}
console.log(factorialize(5));