Skip to content

Instantly share code, notes, and snippets.

View moharan's full-sized avatar

Rangi Becerra moharan

View GitHub Profile
@moharan
moharan / array.js
Created April 27, 2019 19:48
Multidimensional arrays
// Arrays
const element = ["purple", 1, 3 + 5, "juan" + 4, function saludar(){console.log("holi")}, ["Lunes", "Martes", "Miercoles"], [1, 2, 3, 4,[0, "3er level"]]];
console.log(element);
console.log(element[4]);
element[4]();
console.log(element[5][2]);
console.log(element[6][4][1]);
@moharan
moharan / array.js
Created April 27, 2019 19:14
Function to identify an element into array, if is true (delete) and it is false (add)
// Arrays
const colors = ["purple", "yellow", "red", "white", "black"];
//console.log(colors[1]);
//console.log(colors.indexOf("yellow"));
//console.log(colors.indexOf("pink"));
// function to erase element
function eraseElementArray(element, array) {
const result = array.indexOf(element);
@moharan
moharan / array.js
Created April 27, 2019 18:10
Matrices (method)
// Arrays
const days = [
"Lunes",
"Martes",
"Miercoles",
"Jueves",
"Viernes",
"Sabado",
"domingo"
]
@moharan
moharan / array.js
Created April 27, 2019 17:01
Matrices (Array)
// Normal
const brand1 = "Ford",
brand2 = "Seat",
brand3 = "Mercedes",
brand4 = "Porsch",
brand5 = "BMW";
// Arrays
// Save information with a relationship
const autoBrands = [
@moharan
moharan / reduce.js
Created January 29, 2018 14:22
Working with reduce using forEach and exception reduceRight
// Working with forEach
const numbers = [1, 2, 3, 4, 5];
var total = 0;
numbers.forEach(function (number) {
total += number;
});
console.log('Working with forEach: ' + total);
// Working with reduce
var total_reduce = [1, 2, 3, 4, 5].reduce(function (accumulator, current, index) {
@moharan
moharan / filter.js
Last active January 26, 2018 18:36
Differents Filter using: For, forEach, filter and arrow function
const colors = [
{
color: "red",
value: "#f00"
},
{
color: "yellow",
value: "#0f0"
},
{
@moharan
moharan / map.js
Last active January 25, 2018 21:17
Differents Map using: For, forEach, map and arrow function
const colors = [
{
color: "red",
value: "#f00"
},
{
color: "green",
value: "#0f0"
},
{
@moharan
moharan / ejercicio_fp11.JS
Created December 8, 2017 18:38
Paradigmas de programación Ejercicio
const createNote = text => ({
text: text,
createdAt: new Date(),
completed: false,
toString: function (){
return noteToString(this);
}
}); // debes implementar esta función ;-)
const noteToString = note => [
@moharan
moharan / ejercicio_oop09.JS
Created December 8, 2017 18:28
Paradigmas de programación Ejercicio
function Note(text) {
this.text = text || '';
this.createdAt = new Date();
this.completed = false;
}
// [X] | Mon Jun 12 2017 | mundo
Note.prototype.toString = function () {
let str = '[' + (this.completed ? 'X' : ' ') + ']';
str += ' | ' + this.createdAt.toDateString();
str += ' | ' + this.text;
@moharan
moharan / ejercicio_procedimiento07.js
Created December 8, 2017 18:23
Paradigmas de programación Ejercicio
function isPrime(num) {
var isPrime = true;
for (var i = 2; i <= num/2; i++){
if (num % i === 0) {
isPrime = false;
}
}
return isPrime;
}