This file contains 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 all_properties(obj) | |
{ | |
return Object.getOwnPropertyNames(obj); | |
} | |
console.log(all_properties(Math)); | |
console.log(all_properties(Array)); |
This file contains 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 invert_key_value(obj) { | |
var result = {}; | |
var keys = _keys(obj); | |
for (var i = 0, length = keys.length; i < length; i++) { | |
result[obj[keys[i]]] = keys[i]; | |
} | |
return result; | |
} | |
function _keys(obj) | |
{ |
This file contains 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
// === Arrays | |
var [a, b] = [1, 2]; | |
console.log(a, b); | |
//=> 1 2 | |
// Use from functions, only select from pattern | |
var foo = () => [1, 2, 3]; |
This file contains 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 currentYPosition() { | |
if (self.pageYOffset) return self.pageYOffset; | |
if (document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop; | |
if (document.body.scrollTop) return document.body.scrollTop; | |
return 0; | |
} | |
function elmYPosition(eID) { | |
let elm = document.getElementById(eID); | |
let y = elm.offsetTop; |
This file contains 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
// Object destructuring | |
var someObject = { | |
a: 1, | |
b: 2, | |
c: 3, | |
d: 4 | |
}; | |
var {a, b, ...remaining} = someObject; | |
console.log(someObject); // {a: 1, b: 2, c: 3, d: 4} (stays unchanged) |
This file contains 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 ItemsApp extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
items: ['a','b','c','d','e','f','g','h','i','j','k','2','4','1','343','34','a','b','c','d','e','f','g','h','i','j','k','2','4','1','343','34','a','b','c','d','e','f','g','h','i','j','k','2','4','1','343','34','33'], | |
currentPage: 1, | |
itemsPerPage: 30 | |
}; |
This file contains 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
/* HOC fundamentally is just a function that accepts a Component and returns a Component: | |
(component) => {return componentOnSteroids; } or just component => componentOnSteroids; | |
Let's assume we want to wrap our components in another component that is used for debugging purposes, | |
it just wraps them in a DIV with "debug class on it". | |
Below ComponentToDebug is a React component. | |
*/ | |
//HOC using Class | |
//it's a function that accepts ComponentToDebug and implicitly returns a Class | |
let DebugComponent = ComponentToDebug => class extends Component { |
This file contains 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
module.exports = function Flatten(arrays) { | |
return arrays.reduce((acc, item) => { | |
const isArray = Array.isArray(item); | |
const newItems = isArray ? Flatten(item) : [item]; | |
return acc.concat(newItems); | |
}, []) | |
} |
This file contains 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 Bar = props => { | |
const { data } = props; | |
const [showButton, setShowButton] = useState(); | |
const parsedData = buildArrayFromGateway(data); | |
React.useEffect(() => { | |
if(parsedData) { | |
setShowButton(true); | |
} else { | |
setShowButton(false); |
OlderNewer