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
import {assert} from 'chai'; | |
export namespace Dictionaries { | |
/** | |
* Create a deep copy of a dictionary such that all of the origina keys are maintained | |
* and copied into a new dictionary. | |
* | |
* This is used when we have to create a copy of a dictionary to prevent concurrent mutation | |
* or when we need to copy it and then make changes to the new dictionary. |
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
import {assert} from 'chai'; | |
/** | |
* Implement a class named ring buffer with fixed capacity such that | |
* | |
* constructor: takes the capacity for the ring buffer | |
* | |
* push: adds a value to the ring buffer. | |
* pop: removes the last value from the ring buffer or undefined if it's empty. | |
* peek: returns the current value of the most recent value added or undefined if none have been added |
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
import React from 'react'; | |
/** | |
* Implement a replacement for useState which keeps values in the localStorage. | |
* | |
* The idea here is that all calls to use useState can be replaced with | |
* useLocalStorageState(key, initialValue) and implement the same behavior. | |
* | |
* The first time useLocalStorageState is called the value will be initialValue | |
* because nothing is stored in localStorage. |
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
import styled, { css } from 'styled-components'; | |
/* | |
* Switching <ul> element to <ol> and styling | |
*/ | |
const UnorderedList = styled.ul` | |
list-style: circle; | |
li { | |
text-transform: uppercase; | |
margin-bottom: 8px; |
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
import styled, { css } from 'styled-components'; | |
/* | |
* Switching <ul> element to <ol> | |
*/ | |
const UnorderedList = styled.ul` | |
list-style: circle; | |
li { | |
text-transform: uppercase; |
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
import styled from 'styled-components' | |
const Item = styled.li` | |
color: cadetblue; | |
`; | |
const UnorderedList = styled.ul` | |
list-style: none; | |
${Item} { |
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 composition is a way to combine several simpler function into a more complicated one. | |
const readFromTextInput = (): string => { | |
// some pseudocode | |
return "abcde" | |
} | |
const addSignature = (input: string): string => { | |
return input + 'Hello AI.'; | |
} |
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
/** | |
* | |
* @param {string} variable (--variable) | |
* @param {HTMLElement} element (document.documentElement) | |
* @param {string} pseudoElt (:after) | |
*/ | |
function getCssVariable(variable, element = document.documentElement, pseudoElt) { | |
const isValid = /--[\S]*/g; | |
let propertyValue = ''; |
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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import UnorderedList from './UnorderedList'; | |
const App = () => ( | |
<UnorderedList> | |
<li>Item X</li> | |
<li>Item Y</li> | |
</UnorderedList> | |
); |
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
import styled, { css } from 'styled-components'; | |
/** | |
* Extending from another component | |
*/ | |
const List = styled.ul` | |
list-style: auto; | |
li { | |
text-transform: uppercase; |
NewerOlder