Only works if you are converting your Markdown to HTML
<a href="https://www.rust-lang.org/">rust-lang website</a>
Example:
const word = 'hello'; | |
class Hello extends React.Component { | |
state={loud: false} | |
handleLoudness = () => { | |
this.setState({ | |
loud: !this.state.loud | |
}) |
const SayHello = () => ( | |
<Hello | |
render={({ loud, word, handleLoudness }) => ( | |
<h1> | |
<b onClick={handleLoudness}> | |
{loud ? word : word.toUpperCase()}</b> | |
</h1> | |
)} | |
/> | |
); |
const SayHelloWithName = () => ( | |
<Hello | |
render={({loud, handleLoudness }) => ( | |
<h1> | |
<b onClick={handleLoudness}> | |
{loud ? `${word} Quinn` : `${word.toUpperCase()} Quinn `} | |
</b> | |
</h1> | |
)} | |
/> |
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
const countMachine = Machine({ | |
id: 'doubleCounter', | |
initial: 'idle', | |
context: { | |
count: 0 | |
}, | |
states: { | |
idle: { | |
on: { | |
INC_COUNT_TWICE: { |
const soundMachine = Machine({ | |
id: 'soundMachine', | |
initial: 'choose', | |
states: { | |
choose: { | |
on: { | |
PLAY_RED: { | |
actions: (context, event) => console.log(context, events) | |
} | |
} |
const soundMachine = Machine({ | |
id: 'sound', | |
initial: 'playRed', | |
states: { | |
playRed: { | |
entry: ['playRedSound'] | |
}, | |
} |
function ChangeMaker(price, payment) {
let priceInCents = Math.round(price * 100)
let paymentInCents = payment.reduce((acc, curr) => {
return acc += curr
}) * 100
if (paymentInCents > priceInCents){
console.log('can purchase, subtract the amount given from the price')
a. First, I would fix the spelling of the function to is_palindrome
and give the variables within the function more semantic meaning. (i.e. s
could be string
).
Next, I would tackle time and space complexity. In the first for
loop we are recreating s
which already exists and incurring an O(n^2)
time complexity while doing it. This is because strings in Python are immutable. So our first loop is O(n)
and the act of recreating our r
string on each pass is also O(n)
giving us an O(n^2)
time complexity. Creating a new string in memory also gives us an O(n)
space complexity.
Lastly, there is no reason to set our x
value to True
on each iteration. If the reversed string and the string do not match, then it isn't a palindrome and we can immediately return False
.
I would improve this code by creating two pointers: a left index (0) and a right index (length of the string minus one). Then while the left index is less than the right index, I would check to see if the input string's value at