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 arr = [1, 1, 12, 4, 4, true, false, true, null]; | |
const filteredArr = [...new Set(arrr)] | |
// result: [1, 12, 4, true, false, null] |
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
// src/App.js | |
import React from "react"; | |
const UserContext = React.createContext(); | |
export default function App() { | |
const user = { name: "Reed" }; | |
return ( |
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
let cars = [ | |
{ | |
"color": "purple", | |
"type": "minivan", | |
"registration": new Date('2017-01-03'), | |
"capacity": 7 | |
}, | |
{ | |
"color": "red", | |
"type": "station wagon", |
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
// basic uses | |
// user component using useState | |
const User = () => { | |
const [userDetails, setUserdetails] = useState(); | |
const [loading, setLoading] = useState(false); | |
const [error, setError] = useState(); | |
useEffect(() => { | |
setLoading(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
import React, { useEffect, useState } from "react"; | |
export default function WindowResize() { | |
const [windowWidth, setWindowWidth] = useState(window.innerWidth); | |
const handleWindowResize = () => setWindowWidth(window.innerWidth) | |
useEffect(() => { | |
window.addEventListener('resize', handleWindowResize); |
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
export default function UseRef() { | |
const [name, setName] = useState(''); | |
const renderCount = useRef(1); | |
const prevName = useRef(''); | |
useEffect(() => { | |
renderCount.current = renderCount.current + 1 | |
prevName.current = name; | |
}) |
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
$mobileMin: 0px; | |
$mobileMax: 425px; | |
$tabletMin: 426px; | |
$tabletMax: 700px; | |
$laptopMin: 941px; | |
$laptopMax: 1440px; | |
$desktopMin: 1441px; | |
$desktopMax: 1920px; | |
$largeDisplayMin: 1921px; |
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
def clean_json(hash) | |
invalid_values = ["N/A", "-", ""] | |
hash.each do |key, value| | |
if value.is_a?(Hash) | |
clean_json(value) | |
if value.values.any? { |v| invalid_values.include?(v) } | |
hash.delete(key) | |
end | |
elsif value.is_a?(Array) | |
value.each do |v| |
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 str = "cats AND*Dogs-are Awesome"; | |
// const str = 'a b c d-e-f%g' | |
const splitted_word = str.split(/\W+/); | |
const result = | |
splitted_word[0].toLocaleLowerCase() + | |
splitted_word | |
.slice(1) | |
.slice(-splitted_word.length) | |
.map((s) => s.charAt(0).toUpperCase() + s.slice(1).toLocaleLowerCase()) | |
.join(""); |