Skip to content

Instantly share code, notes, and snippets.

View jordanhudgens's full-sized avatar

Jordan Hudgens jordanhudgens

View GitHub Profile
user = {
name: 'Kristine',
favorites: {
food: 'Pizza',
movies: 'Fiddler on the Roof'
}
}
user.dig(:name) # => "Kristine"
user.dig(:favorites) # => {:food=>"Pizza", :movies=>"Fiddler on the Roof"}
class SubArraySplitter {
constructor(arr, num) {
this.arr = arr;
this.num = num;
this.splitArray = [];
this.iterate();
}
iterate() {
while (this.arr.length > 1) {
const functionalFizzBuzz = n => {
return Array.from(
{ length: n },
(_, idx) =>
[[15, "fizzbuzz"], [5, "buzz"], [3, "fizz"]].find(
val => (idx + 1) % val[0] === 0
) || idx + 1
).reduce((acc, el) => (acc += (el[1] || el) + "\n"), "");
const maxStringCounter = str => {
const obj = {};
const splitStr = str.split("").filter(el => el !== " ");
splitStr.forEach(el => {
if (obj[el]) {
return (obj[el] += 1);
} else {
return (obj[el] = 1);
}
class FlexibleCounter {
constructor(nums, op) {
this.nums = nums;
this.op = op;
this.operatorWhiteList = ["+", "*", "/", "-"];
}
result() {
if (this.operatorWhiteList.includes(this.op) && !this.nums.some(isNaN)) {
return this.nums.reduce((total, el) => eval(`${total} ${this.op} ${el}`));
const sample = arr => {
const randomIndex = Math.floor(Math.random() * arr.length);
return arr[randomIndex];
};
sample([1, 2, 3]); // 3
sample([90, 500, 100, -20]); // 500
const isPalindrome = str => {
return (
str
.split("")
.reverse()
.join() === str
);
};
isPalindrome("tacocat"); // true
const isPalindrome = (str) => {
return str.split('').reverse().join() === str.split('').join();
}
isPalindrome('tacocat'); // true
isPalindrome('racecar'); // true
isPalindrome('asdf'); // false
isPalindrome('nope'); // false
const userOne = {
firstName: "Kristine",
lastName: "Hudgens"
};
const userTwo = {
firstName: "Tiffany",
lastName: "Hudgens"
};
function ageVerification(age) {
// if (age > 25) {
// console.log('can rent a car');
// } else {
// console.log("can't rent a car");
// }
return age > 25 ? "can rent a car" : "can't rent a car";
}