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, {useState, useMemo} from 'react'; | |
// Define an arrayValue prop | |
const UseMemoComponent = ({arrayValue}) => { | |
// Create an object with the arrayValue prop | |
const myArray = useMemo(() => { | |
// If the value is undefined, default to 1 | |
const myValue = arrayValue || 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
import React, {useState, useCallback} from 'react'; | |
// Define an arrayValue prop | |
const UseCallbackComponent = ({arrayValue}) => { | |
// Memoize callback with useCallback | |
// Ensure the reference is always the same as long as the function doesn't change | |
// So children components do not re-render due to a redundant variable reference change | |
// Since functions are pass by reference | |
const createArray = useCallback(() => { |
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, {useState, useMemo} from 'react'; | |
// Import the useSelector hook from the react-redux package | |
import { useSelector } from 'react-redux' | |
const UseSelectorComponent = ({arrayValue}) => { | |
// Retrieve myArray from the Redux store | |
const myArray = useSelector(state => state.myArray); | |
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
const moment = require('moment'); | |
const databaseDate = '06/01/2021 9:59:01 PM GMT+2'; | |
const jsDate = moment(databaseDate); | |
console.log(jsDate); | |
// > Tue Jun 01 2021 21:59:01 GMT+0200 | |
// Calculate time difference from now | |
console.log(jsDate.fromNow()); |
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 moment = require('moment'); | |
const databaseDate = '06/01/2021 9:59:01 PM GMT+2'; | |
var jsDate = moment(databaseDate, "DD/MM/YYYY HH:mm:ss"); | |
console.log(jsDate); | |
// > Wed Jan 06 2021 09:59:01 GMT+0100 (CET) | |
// Calculate time difference from now | |
console.log(jsDate.fromNow()); |
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
new Date().getTime() | |
< 1614547103822 |
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
new Date(1614547103822) | |
// < Sun Feb 28 2021 22:18:23 GMT+0100 (CET) |
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 java.util.ArrayList; | |
// Let's develop our first solution | |
public class CountingDuplicates { | |
public static int duplicateCount(String text) { | |
// We need to count the amount of characters which have duplicates (not the amount of duplicates) | |
int totalCharsWithDupes = 0; | |
// Keep an array of characters which have already been counted towards the totalDupes counter | |
// Since we want to count the amount of characters which have duplicates |
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 java.util.HashMap; | |
import java.util.Map; | |
public class CountingDuplicates { | |
public static int duplicateCount(String text) { | |
// Keep our a list with the number of duplicates per character | |
// HashMap<Character, NumberOfDuplicates> | |
HashMap<Character, Integer> hashMap = new HashMap<Character, Integer>(); | |
// Let's only loop once over the full input |