Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Retos/ejercicio-recursividad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @author Dimacros
*
* Problema:
* Las parejas de números que sumen 8; sin usar un loop.
*
* Ejemplo: [3, 6, 2, -6, 10, -2, 0, 8, 4, 4]
*
* return [ [ 6, 2 ], [ 10, -2 ], [ 0, 8 ], [4, 4] ]
*/

const numbers = [3, 6, 2, -6, 10, -2, 0, 8, 4, 4];

function sumPairsEquals(total, numbers)
{
const maxLenghtAllowed = 2;

if (numbers.length < maxLenghtAllowed) {
return accumulator();
}

[a, b, ...etc] = numbers;

if (a + b === total) {
accumulator().push([a, b]);
}

return sumPairsEquals(total, reduceLenght(numbers, 1));
}

function reduceLenght(numbers, length)
{
return numbers.slice(length);
}

function accumulator()
{
if( typeof accumulator.add === 'undefined' ) {
accumulator.add = [];
}

return accumulator.add;
}

console.log(
sumPairsEquals(8, numbers)
);
12 changes: 12 additions & 0 deletions Retos/sesion3-reto1/app/Album.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Album
{
/**
* @param {String} title
*/
constructor(title)
{
this.title = title;
}
}

module.exports = Album;
12 changes: 12 additions & 0 deletions Retos/sesion3-reto1/app/Artist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Artist
{
/**
* @param {String} name
*/
constructor(name)
{
this.name = name;
}
}

module.exports = Artist;
16 changes: 16 additions & 0 deletions Retos/sesion3-reto1/app/Factories/SongFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const Artist = require("../Artist");
const Album = require("../Album");
const Song = require("../Song");

class SongFactory
{
create({artist: { name: artistName}, album: { title: albumTitle}, title, durationInSeconds})
{
const artist = new Artist(artistName);
const album = new Album(albumTitle);

return new Song(artist, album, title, durationInSeconds);
}
}

module.exports = SongFactory;
11 changes: 11 additions & 0 deletions Retos/sesion3-reto1/app/Factories/UserFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const User = require('../User');

class UserFactory
{
create(username)
{
return new User(username);
}
}

module.exports = UserFactory;
22 changes: 22 additions & 0 deletions Retos/sesion3-reto1/app/PlayList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class PlayList
{
/**
* @param {String} title
*/
constructor(title)
{
this.title = title;
this.songs = new Array;
}

/**
*
* @param {Song} song
*/
addSong(song)
{
this.songs.push(song);
}
}

module.exports = PlayList;
19 changes: 19 additions & 0 deletions Retos/sesion3-reto1/app/Song.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Song
{
/**
*
* @param {Artist} artist
* @param {Album} album
* @param {String} title
* @param {Number} durationInSeconds
*/
constructor(artist, album, title, durationInSeconds)
{
this.artist = artist;
this.album = album;
this.title = title;
this.durationInSeconds = durationInSeconds;
}
}

module.exports = Song;
36 changes: 36 additions & 0 deletions Retos/sesion3-reto1/app/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const PlayList = require("./PlayList");

class User
{
/**
* @param {String} username
*/
constructor(username)
{
this.username = username;
this.playLists = new Array;
}

/**
* @param {String} title
*/
addPlayList(title)
{
this.playLists.push(new PlayList(title));
}

/**
* @param {String} title
*/
myPlayList(title)
{
return this.playLists.find(playList => playList.title === title);
}

myPlayLists()
{
return this.playLists;
}
}

module.exports = User;
49 changes: 49 additions & 0 deletions Retos/sesion3-reto1/bootstrap/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const SongFactory = require("../app/Factories/SongFactory");
const UserFactory = require("../app/Factories/UserFactory");

class Spotify
{
/**
* @param {SongFactory} songFactory
* @param {UserFactory} UserFactory
*/
constructor(songFactory, userFactory)
{
this.songFactory = songFactory;
this.userFactory = userFactory;
this.songs = new Array;
this.users = new Array;
}

createSong(song)
{
this.songs.push(this.songFactory.create(song));
}

createUser(username)
{
this.users.push(this.userFactory.create(username));
}

findUserByUsername(username)
{
return this.users.find(user => user.username === username);
}

findSongByTitle(title)
{
return this.songs.find(song => song.title === title);
}

allSongs()
{
return this.songs;
}

allUsers()
{
return this.users;
}
}

module.exports = new Spotify(new SongFactory, new UserFactory);
52 changes: 52 additions & 0 deletions Retos/sesion3-reto1/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
{
"artist": {
"name": "PXNDX"
},
"album": {
"title": "-"
},
"title": "Los Malaventurados lo lloran",
"durationInSeconds": 300
},
{
"artist": {
"name": "Tragokorto"
},
"album": {
"title": "¿A dónde vas?"
},
"title": "Borracho en el bar",
"durationInSeconds": 300
},
{
"artist": {
"name": "Los Violadores"
},
"album": {
"title": "-"
},
"title": "Sentimiento Fatal",
"durationInSeconds": 300
},
{
"artist": {
"name": ""
},
"album": {
"title": ""
},
"title": "",
"durationInSeconds": 300
},
{
"artist": {
"name": ""
},
"album": {
"title": ""
},
"title": "",
"durationInSeconds": 300
}
]
61 changes: 23 additions & 38 deletions Retos/sesion3-reto1/instrucciones.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,35 @@
*
* La cantidad y complejidad de las estructuras de datos es libre.
*
* */
*/

// Codigo Referencia
const spotify = require('./bootstrap/app');
const data = require('./data.json');

class Autor {
constructor(nombre, pais) {
this.nombre = nombre;
this.pais = pais;
}
}
spotify.createUser('dimacros');

class Cancion {
constructor(titulo, duracion, autor) {
this.titulo = titulo;
this.duracion = duracion;
this.autor = new Autor(autor.nombre, autor.pais);
}
}
data.forEach(song => {
spotify.createSong(song);
});

class db {
constructor(canciones) {
this.canciones = canciones;
}
}
const dimacros = spotify.findUserByUsername('dimacros');

let SpotifyDB;
dimacros.addPlayList('Rock');
dimacros.addPlayList('Electro');
dimacros.addPlayList('Salsa');

function Spotify () {
return {
init: function () {
SpotifyDB = new db([]);
},
agregarCancion: function (titulo, duracion, autor) {
SpotifyDB.canciones.push(new Cancion(titulo, duracion, autor));
}
}
}
dimacros.myPlayList('Rock').addSong(
spotify.findSongByTitle('Los Malaventurados lo lloran')
);

let spotifyInstance = Spotify();
dimacros.myPlayList('Rock').addSong(
spotify.findSongByTitle('Borracho en el bar')
);

spotifyInstance.init();
dimacros.myPlayList('Rock').addSong(
spotify.findSongByTitle('Sentimiento Fatal')
);

spotifyInstance.agregarCancion('cancion uno', 4.3, {nombre: 'tanto', pais: 'tanto'});
spotifyInstance.agregarCancion('cancion dos', 4.3, {nombre: 'tanto', pais: 'tanto'});


console.log(SpotifyDB);
console.log(
dimacros.myPlayList('Rock')
);