This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SubArraySplitter { | |
constructor(arr, num) { | |
this.arr = arr; | |
this.num = num; | |
this.splitArray = []; | |
this.iterate(); | |
} | |
iterate() { | |
while (this.arr.length > 1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), ""); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isPalindrome = str => { | |
return ( | |
str | |
.split("") | |
.reverse() | |
.join() === str | |
); | |
}; | |
isPalindrome("tacocat"); // true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isPalindrome = (str) => { | |
return str.split('').reverse().join() === str.split('').join(); | |
} | |
isPalindrome('tacocat'); // true | |
isPalindrome('racecar'); // true | |
isPalindrome('asdf'); // false | |
isPalindrome('nope'); // false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const userOne = { | |
firstName: "Kristine", | |
lastName: "Hudgens" | |
}; | |
const userTwo = { | |
firstName: "Tiffany", | |
lastName: "Hudgens" | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} |