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 FirstReverse(str) { | |
// the new string, reversed, that will be returned. | |
let newString = ''; | |
// at each iteration, i is the size of the string less one (right index), | |
// while str.length - 1 is above zero, | |
// subtract 1 | |
for (var i = str.length - 1; i >= 0; i--) { | |
// at each index iteration, the newString will receive a character that is the | |
// character at the current index (str.length -1), | |
// then the index will shorten by one at every iteration. |
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
/* setState always calls render again and it is async */ | |
/* Calling UPPERCASE onClick with React */ | |
class ClickExample extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { name: "tim" }; | |
} |
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
/* Controlled Component With Update */ | |
<input | |
type='text' | |
name='inputText' | |
value={this.state.inputText} | |
onChange={(e) => { | |
this.setState({inputText: e.target.value}) | |
}} | |
/> |
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
/* Form on submit */ | |
<form onSubmit={(e) => { | |
e.preventDefault(); | |
const data = [...this.state.data, | |
this.state.inputText]; | |
this.setState({data, inputText: ''}); | |
}}> | |
<input | |
type='text' | |
name='inputText' |
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
/** | |
* Return the longest word in a sentence | |
* Loop through an array of the words split from the string and compare the lengths | |
* 1 - Strip away any punctuation | |
* 2 - Separe the sentence into a list of words to retrieve words and lengths | |
* 3 - Loop through the list and comparte the words lenghts | |
*/ | |
// Match only what contains a-z case unsensitive or numbers | |
function LongestWOrd(sen) { |
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
/** | |
* Capitalize the first letter of each word | |
* 1) Create an array of words separating by spaces " " with split | |
* 2) At each word get the element 0 and capitalize it in a loop | |
* 3) Concatenate the words back into a string | |
*/ | |
function LetterCapitalize(str) { | |
var words = str.split(" "); |
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
// This challenge requires you to add up all the numbers from 1 to a given argument. For example, if the parameter num is 4, your program should add up 1 + 2 + 3 + 4 and return 10. This will be pretty simple to write out as a loop. We'll maintain a variable and keep adding to it as we loop from 1 to num. | |
function SimpleAdding(num) { | |
let sum = 0; | |
for (i = 0; i <= num; i++) { | |
sum = sum + i; | |
} | |
return sum; | |
} |
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 LetterChanges(str){ | |
// Firt get all the leters, global insensitive, then run a function that receives a char | |
// Takes char, if it is z or Z change it to 'a' | |
// Then convert to charCode and add 1. | |
let converted = str.replace(/[a-z]/gi, function(char){ | |
return(char === 'z'|| char ==='Z') ? 'a' : String.fromCharCode(char.charCodeAt() + 1); | |
}); | |
// Find if the letter is a vowel the Upper Case it and replace it to the array. | |
let capsVowel = converted.replace(/a|e|i|o|u/gi, function(vowel) { | |
return vowel.toUpperCase(); |
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 WarningBanner(props) { | |
if (!props.warn) { | |
return null; | |
} | |
return ( | |
<div className="warning"> | |
Warning! | |
</div> | |
); |
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
/** | |
* | |
This challenge requires you to determine if every alphabetic character in a string has a plus (+) symbol on the left and right side of itself. For example: the string "+a+b+c+" is good but the string "===+3+f=+b+" is not because the "f" does not have a plus symbol to its right. A very simple way to solve this challenge is to create a loop that every time it gets to an alphabetic character, it checks to see if it is surrounded by + symbols. | |
*/ | |
/* Not pure f */ | |
function SimpleSymbols(str) { | |
var str = "=" + str + "="; | |
for (var i = 0; i < str.length; i++) { |
OlderNewer