Skip to content

Instantly share code, notes, and snippets.

View moharan's full-sized avatar

Rangi Becerra moharan

View GitHub Profile
//palíndromo [3,2,5,2,3] == True palindromo [3,2,5,6,2,3] == False
var element0 = [3, 2, 5, 2, 3];
var element1 = ["x", "s"];
var element2 = [3, 2, 5, 6, 2, 3];
//forma funcional
var palindromof = x => {
x = x + "";
var invertir = x.split("").reverse().join("");
//comparación
return x == invertir;
//string “Laboratoria Rocks”
var element = "Laboratoria Rocks";
//forma clásica
var invertir = x => {
x = x + "";
return x.split("").reverse().join("");
}
// forma funcional
// https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Array/reduceRight
var invertirf = element.split("").reduceRight((x, y) => {
//forma funcional
var element = [
{
name: 'Rangi',
mail: 'rangibecerra@gmail.com',
date: '26-01-1985'},
{
name: 'Mohana',
mail: 'moharan28@hotmail.com',
date:'27-02-1895'},
//invertir un número
var invertir = x => {
if (x === "") {
return "";
}
else {
//console.log(x);
return invertir(x.substr(1)) + x.charAt(0);
}
}
//si un número es positivo
var positivo = x => {
if(x>0) {
return true;
} else {
return false;
}
}
console.log(positivo(5));
console.log(positivo(-2));
//forma funcional
var alumnos = [
{
nombre: 'Pedro',
notas: [4, 4, 4]
}, {
nombre: 'Juan',
notas: [7, 7, 7, 7]
}, {
nombre: 'Diego',
(function (){
var loop = [];
for (var i = 1; i <= 100; i++) {
loop.push(i);
if (i % 3 === 0 && i % 5 === 0) {
loop.push("beetrack");
}
else if (i % 3 === 0) {
var add = (a,b) => {
var sum = function (b){
return a+b;
};
if(typeof b == "undefined"){
return sum;
}else{
return sum(b);
}
}
var duplicate = (array) => {
return array + "," + array;
}
console.log(duplicate([4,3,2,1,0]));
@moharan
moharan / ejercicio_imperativo04.js
Created December 8, 2017 18:17
Paradigmas de programación Ejercicio
function printPrimes() {
// Ahora debemos iterar desde `2` hasta `i / 2` usando una variable `j` como
// contador.
for (var i = 2; i < 20; i++) {
var isPrime = true;
for (var j = 2; j <= i/2; j++){
// Para cada `j` comprueba si la división `i / j` deja un residuo.
if (i % j === 0) {
isPrime = false;
}