Last active
June 6, 2018 12:10
-
-
Save Whistler092/b5d741e12e48e975b15ed5d522e5845f to your computer and use it in GitHub Desktop.
Guia de fundamentos de js
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
function handleError(err){ | |
console.log(`Request Failed: ${err}`) | |
} | |
async function getLuke(){ | |
try { | |
const response = await fetch("http://swapi.co/api/people/1/") | |
const luke = await response.json() | |
const responseHomeWord = await fetch(luke.homeworld) | |
luke.homeworld = await responseHomeWord.json() | |
console.log(`${luke} naciò en ${luke.homeworld.name}`) | |
} catch (error) { | |
handleError(err) | |
} | |
} |
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
// Complete the pangrams function below. | |
function pangrams(s) { | |
let arr = [] | |
s = s.toLowerCase().replace(/\s/g, "") | |
for(let i = 0; i < s.length; i++){ | |
let element = s[i] | |
if(arr.indexOf(element) == -1){ | |
arr.push(element) | |
} | |
} | |
console.log("arr", arr); | |
//eiou | |
if(arr.length == 26){ | |
return `pangram`; | |
}else { | |
return `not pangram`; | |
} | |
} |
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
/* | |
Hay varias formas de concatenar un string | |
*/ | |
console.log("El área de un triángulo de base 5 y altura 7 es: " + 5 * 7 / 2) | |
console.log(`El área de un triángulo de base 5 y altura 7 es: " ${5 * 7 / 2}`) | |
/* | |
Funciones | |
*/ | |
let base = 5 | |
let height = 7 | |
/* | |
//Funcion Anonima | |
function (){ | |
}*/ | |
function triagleArea(base,height){ | |
return base * height / 2 | |
} | |
console.log(`El área de un triángulo de base | |
${base} y altura ${height} es: " ${triagleArea(base,height)}`) | |
/* | |
Arrow Function | |
A una variable se le puede asignar una funcion | |
*/ | |
let triagleArea = function (base,height){ | |
return base * height / 2 | |
} | |
let triagleArea = (base,height) => { | |
// llaves para multiples lineas | |
return base * height / 2 | |
} | |
let triagleArea = (base,height) => base * height / 2 | |
/* | |
Variables | |
Let | |
Const = Son variables que no se pueden cambiar, | |
solo se pueden asignar una sola ves | |
*/ | |
/* | |
Condicionales | |
*/ |
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
/* | |
Arrays: Left Rotation | |
A left rotation operation on an array shifts | |
each of the array's elements unit to the left. | |
For example, if left rotations are performed | |
on array , then the array would become . | |
*/ | |
// Complete the rotLeft function below. | |
function rotLeft(a, d) { | |
console.log("a", a) | |
console.log("d", d) | |
return a.slice(d, a.length).concat(a.slice(0,d)) | |
/* | |
Congratulations, you passed the sample test case. | |
Click the Submit Code button to run your code against all the test cases. | |
Input (stdin) | |
20 10 | |
41 73 89 7 10 1 59 58 84 77 77 97 58 1 86 58 26 10 86 51 | |
Your Output (stdout) | |
77 97 58 1 86 58 26 10 86 51 41 73 89 7 10 1 59 58 84 77 | |
Expected Output | |
77 97 58 1 86 58 26 10 86 51 41 73 89 7 10 1 59 58 84 77 | |
Debug output | |
a [ 41, 73, 89, 7, 10, 1, 59, 58, 84, 77, 77, 97, 58, 1, 86, 58, 26, 10, 86, 51 ] | |
d 10 | |
*/ | |
} | |
/* | |
Strings: Making Anagrams | |
Alice is taking a cryptography class and finding anagrams to be very useful. | |
We consider two strings to be anagrams of each other if the first string's | |
letters can be rearranged to form the second string. | |
In other words, both strings must contain the same exact letters in the | |
same exact frequency For example, bacdc and dcbac are anagrams, | |
but bacdc and dcbad are not. | |
Alice decides on an encryption scheme involving two large strings | |
where encryption is dependent on the minimum number of character | |
deletions required to make the two strings anagrams. | |
Can you help her find this number? | |
Given two strings, and , that may or may not be of the same length, | |
determine the minimum number of character deletions required to make and anagrams. | |
Any characters can be deleted from either of the strings. | |
Input Format | |
The first line contains a single string, . | |
The second line contains a single string, . | |
*/ | |
function main() { | |
const a = readLine(); | |
const b = readLine(); | |
let removed = 0 | |
let total = (a.length + b.length) | |
let aNotIn = 0 | |
for(let i = 0; i < a.length; i++) { | |
let item = a[i] | |
if(!b.includes(item)){ | |
removed++ | |
} | |
} | |
let bNotIn = 0 | |
for(let i = 0; i < b.length; i++){ | |
let item = b[i] | |
if(!a.includes(item)){ | |
removed++ | |
} | |
} | |
console.log(removed) | |
} |
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
public async Task<ActionResult> ProcesosEnParalelo() | |
{ | |
var stopWatch = new StopWatch(); | |
stopWatch.Start(); | |
var tarea1 = Proceso1(); | |
var tarea2 = Proceso2("Felipe"); | |
await Task.WhenAll(tarea1, tarea2); | |
stopWatch.Stop(); | |
var duracionEnSegundos = stopWatch.ElapsedMilliseconds / 1000.0; | |
Console.WriteLine($"Duración En Segundos {duracionEnSegundos}"); | |
Console.WriteLine($"Resultado Proceso Paralelo1 {tarea1.Result}"); | |
Console.WriteLine($"Resultado Proceso Paralelo2 {tarea2.Result}"); | |
} | |
public async Task<int> Proceso1() | |
{ | |
return await Task.Run(() => | |
{ | |
Thread.Sleep(1000); //Simular una tarea larga | |
return 42; //Respuesta | |
}); | |
} | |
public async Task<string> Proceso2(string nombre) | |
{ | |
var tarea = Task.Run(() => | |
{ | |
Thread.Sleep(1000); //Simular una tarea larga | |
return $"Hola, {nombre}"; //Respuesta | |
}).ContinueWith((saludo) => | |
{ | |
return $"Ejemplo de saludo '{saludo}'"; | |
}); | |
var resultado = await tarea; | |
return resultado; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment