Skip to content

Instantly share code, notes, and snippets.

View MorenoMdz's full-sized avatar
🎯
Focusing

MorenoMdz

🎯
Focusing
  • Self
  • Florianópolis
View GitHub Profile
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.
/* 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" };
}
/* Controlled Component With Update */
<input
type='text'
name='inputText'
value={this.state.inputText}
onChange={(e) => {
this.setState({inputText: e.target.value})
}}
/>
/* 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'
/**
* 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) {
/**
* 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 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;
}
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();
@MorenoMdz
MorenoMdz / React_hide-comp.js
Last active May 1, 2018 22:14
React Hidde component conditional example
function WarningBanner(props) {
if (!props.warn) {
return null;
}
return (
<div className="warning">
Warning!
</div>
);
/**
*
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++) {