From a89f7b8c11dd50bc0eeb10ece10a1d1e6c7fe043 Mon Sep 17 00:00:00 2001 From: dimacros Date: Fri, 31 May 2019 00:46:49 -0500 Subject: [PATCH 1/7] Agregar ejercicio de recursividad --- retos/ejercicio-recursividad.js | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 retos/ejercicio-recursividad.js diff --git a/retos/ejercicio-recursividad.js b/retos/ejercicio-recursividad.js new file mode 100644 index 0000000..88c7c8d --- /dev/null +++ b/retos/ejercicio-recursividad.js @@ -0,0 +1,49 @@ +/** + * @author Dimacros + * + * Problema: + * Las parejas de numeros que sumen 8; sin usar un loop. + * + * Ejemplo: [4, 6, 2, -6, 10, -2, 0, 8, 4 ...] + * + * return [ [ 6, 2 ], [ 10, -2 ], [ 0, 8 ] ] + */ + +const numeros = [4, 6, 2, -6, 10, -2, 0, 8, 4]; + +const app = () => console.log( + sumPairsEquals(8, numeros) +); + +app(); + +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, movePointer(numbers, 1)); +} + +function movePointer(numbers, length) +{ + return numbers.slice(length); +} + +function accumulator() +{ + if( typeof accumulator.add === 'undefined' ) { + accumulator.add = []; + } + + return accumulator.add; +} \ No newline at end of file From d019f995504b115eec8b86f061fa2109cf22a918 Mon Sep 17 00:00:00 2001 From: dimacros <31266588+dimacros@users.noreply.github.com> Date: Fri, 31 May 2019 00:59:38 -0500 Subject: [PATCH 2/7] Update ejercicio-recursividad.js --- retos/ejercicio-recursividad.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/retos/ejercicio-recursividad.js b/retos/ejercicio-recursividad.js index 88c7c8d..0eeec91 100644 --- a/retos/ejercicio-recursividad.js +++ b/retos/ejercicio-recursividad.js @@ -15,8 +15,6 @@ const app = () => console.log( sumPairsEquals(8, numeros) ); -app(); - function sumPairsEquals(total, numbers) { const maxLenghtAllowed = 2; @@ -46,4 +44,7 @@ function accumulator() } return accumulator.add; -} \ No newline at end of file +} + +//Run application +return app(); From 7d941e1729e334007c60f11a8a3b593171b3edd4 Mon Sep 17 00:00:00 2001 From: dimacros Date: Fri, 31 May 2019 01:31:23 -0500 Subject: [PATCH 3/7] Unir rama con la principal --- retos/ejercicio-recursividad.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/retos/ejercicio-recursividad.js b/retos/ejercicio-recursividad.js index 88c7c8d..5b838fa 100644 --- a/retos/ejercicio-recursividad.js +++ b/retos/ejercicio-recursividad.js @@ -15,8 +15,6 @@ const app = () => console.log( sumPairsEquals(8, numeros) ); -app(); - function sumPairsEquals(total, numbers) { const maxLenghtAllowed = 2; @@ -46,4 +44,7 @@ function accumulator() } return accumulator.add; -} \ No newline at end of file +} + +//Run application +return app(); \ No newline at end of file From d064379c2bc9aab5a9956a1963f1ff6171bbd3c7 Mon Sep 17 00:00:00 2001 From: dimacros Date: Sun, 2 Jun 2019 21:59:15 -0500 Subject: [PATCH 4/7] =?UTF-8?q?Soluci=C3=B3n=20al=20reto=20de=20Spotify?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ejercicio-recursividad.js | 0 Retos/sesion3-reto1/app/Album.js | 12 ++++ Retos/sesion3-reto1/app/Artist.js | 12 ++++ .../app/Factories/SongFactory.js | 16 ++++++ .../app/Factories/UserFactory.js | 11 ++++ Retos/sesion3-reto1/app/PlayList.js | 22 ++++++++ Retos/sesion3-reto1/app/Song.js | 19 +++++++ Retos/sesion3-reto1/app/User.js | 36 ++++++++++++ Retos/sesion3-reto1/bootstrap/app.js | 49 +++++++++++++++++ Retos/sesion3-reto1/data.json | 52 ++++++++++++++++++ Retos/sesion3-reto1/instrucciones.js | 55 +++++-------------- 11 files changed, 244 insertions(+), 40 deletions(-) rename Retos/{sesion3-reto1 => }/ejercicio-recursividad.js (100%) create mode 100644 Retos/sesion3-reto1/app/Album.js create mode 100644 Retos/sesion3-reto1/app/Artist.js create mode 100644 Retos/sesion3-reto1/app/Factories/SongFactory.js create mode 100644 Retos/sesion3-reto1/app/Factories/UserFactory.js create mode 100644 Retos/sesion3-reto1/app/PlayList.js create mode 100644 Retos/sesion3-reto1/app/Song.js create mode 100644 Retos/sesion3-reto1/app/User.js create mode 100644 Retos/sesion3-reto1/bootstrap/app.js create mode 100644 Retos/sesion3-reto1/data.json diff --git a/Retos/sesion3-reto1/ejercicio-recursividad.js b/Retos/ejercicio-recursividad.js similarity index 100% rename from Retos/sesion3-reto1/ejercicio-recursividad.js rename to Retos/ejercicio-recursividad.js diff --git a/Retos/sesion3-reto1/app/Album.js b/Retos/sesion3-reto1/app/Album.js new file mode 100644 index 0000000..74d8cf8 --- /dev/null +++ b/Retos/sesion3-reto1/app/Album.js @@ -0,0 +1,12 @@ +class Album +{ + /** + * @param {String} title + */ + constructor(title) + { + this.title = title; + } +} + +module.exports = Album; \ No newline at end of file diff --git a/Retos/sesion3-reto1/app/Artist.js b/Retos/sesion3-reto1/app/Artist.js new file mode 100644 index 0000000..7948437 --- /dev/null +++ b/Retos/sesion3-reto1/app/Artist.js @@ -0,0 +1,12 @@ +class Artist +{ + /** + * @param {String} name + */ + constructor(name) + { + this.name = name; + } +} + +module.exports = Artist; \ No newline at end of file diff --git a/Retos/sesion3-reto1/app/Factories/SongFactory.js b/Retos/sesion3-reto1/app/Factories/SongFactory.js new file mode 100644 index 0000000..831a31c --- /dev/null +++ b/Retos/sesion3-reto1/app/Factories/SongFactory.js @@ -0,0 +1,16 @@ +const Artist = require("../Artist"); +const Album = require("../Album"); +const Song = require("../Song"); + +class SongFactory +{ + create({artistData, albumData, title, durationInSeconds}) + { + const artist = new Artist(artistData); + const album = new Album(albumData); + + return new Song(artist, album, title, durationInSeconds); + } +} + +module.exports = SongFactory; \ No newline at end of file diff --git a/Retos/sesion3-reto1/app/Factories/UserFactory.js b/Retos/sesion3-reto1/app/Factories/UserFactory.js new file mode 100644 index 0000000..1146300 --- /dev/null +++ b/Retos/sesion3-reto1/app/Factories/UserFactory.js @@ -0,0 +1,11 @@ +const User = require('../User'); + +class UserFactory +{ + create(username) + { + return new User(username); + } +} + +module.exports = UserFactory; \ No newline at end of file diff --git a/Retos/sesion3-reto1/app/PlayList.js b/Retos/sesion3-reto1/app/PlayList.js new file mode 100644 index 0000000..8b9b699 --- /dev/null +++ b/Retos/sesion3-reto1/app/PlayList.js @@ -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; \ No newline at end of file diff --git a/Retos/sesion3-reto1/app/Song.js b/Retos/sesion3-reto1/app/Song.js new file mode 100644 index 0000000..e3d03d9 --- /dev/null +++ b/Retos/sesion3-reto1/app/Song.js @@ -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; \ No newline at end of file diff --git a/Retos/sesion3-reto1/app/User.js b/Retos/sesion3-reto1/app/User.js new file mode 100644 index 0000000..2b05ec8 --- /dev/null +++ b/Retos/sesion3-reto1/app/User.js @@ -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; \ No newline at end of file diff --git a/Retos/sesion3-reto1/bootstrap/app.js b/Retos/sesion3-reto1/bootstrap/app.js new file mode 100644 index 0000000..728740b --- /dev/null +++ b/Retos/sesion3-reto1/bootstrap/app.js @@ -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); \ No newline at end of file diff --git a/Retos/sesion3-reto1/data.json b/Retos/sesion3-reto1/data.json new file mode 100644 index 0000000..61f3f99 --- /dev/null +++ b/Retos/sesion3-reto1/data.json @@ -0,0 +1,52 @@ +[ + { + "artist": { + "name": "PXNDX" + }, + "album": { + "title": "-" + }, + "title": "Los Malaventurados lo lloran", + "durationInSeconds": 300 + }, + { + "artist": { + "name": "" + }, + "album": { + "title": "" + }, + "title": "", + "durationInSeconds": 300 + }, + { + "artist": { + "name": "" + }, + "album": { + "title": "" + }, + "title": "", + "durationInSeconds": 300 + }, + { + "artist": { + "name": "" + }, + "album": { + "title": "" + }, + "title": "", + "durationInSeconds": 300 + }, + { + "artist": { + "name": "" + }, + "album": { + "title": "" + }, + "title": "", + "durationInSeconds": 300 + } +] \ No newline at end of file diff --git a/Retos/sesion3-reto1/instrucciones.js b/Retos/sesion3-reto1/instrucciones.js index 3e2793e..b4f3c6b 100644 --- a/Retos/sesion3-reto1/instrucciones.js +++ b/Retos/sesion3-reto1/instrucciones.js @@ -10,50 +10,25 @@ * * 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(); - -spotifyInstance.init(); - -spotifyInstance.agregarCancion('cancion uno', 4.3, {nombre: 'tanto', pais: 'tanto'}); -spotifyInstance.agregarCancion('cancion dos', 4.3, {nombre: 'tanto', pais: 'tanto'}); - - -console.log(SpotifyDB); \ No newline at end of file +console.log(dimacros); \ No newline at end of file From 03db8bdac3b30a390e3b3d75d0379c7247f02d15 Mon Sep 17 00:00:00 2001 From: dimacros Date: Sun, 2 Jun 2019 22:15:24 -0500 Subject: [PATCH 5/7] =?UTF-8?q?Agregar=20m=C3=A1s=20datos=20de=20Prueba?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Retos/sesion3-reto1/data.json | 12 ++++++------ Retos/sesion3-reto1/instrucciones.js | 12 +++++++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Retos/sesion3-reto1/data.json b/Retos/sesion3-reto1/data.json index 61f3f99..201bf72 100644 --- a/Retos/sesion3-reto1/data.json +++ b/Retos/sesion3-reto1/data.json @@ -11,22 +11,22 @@ }, { "artist": { - "name": "" + "name": "Tragokorto" }, "album": { - "title": "" + "title": "¿A dónde vas?" }, - "title": "", + "title": "Borracho en el bar", "durationInSeconds": 300 }, { "artist": { - "name": "" + "name": "Los Violadores" }, "album": { - "title": "" + "title": "-" }, - "title": "", + "title": "Sentimiento Fatal", "durationInSeconds": 300 }, { diff --git a/Retos/sesion3-reto1/instrucciones.js b/Retos/sesion3-reto1/instrucciones.js index b4f3c6b..d74cc2d 100644 --- a/Retos/sesion3-reto1/instrucciones.js +++ b/Retos/sesion3-reto1/instrucciones.js @@ -31,4 +31,14 @@ dimacros.myPlayList('Rock').addSong( spotify.findSongByTitle('Los Malaventurados lo lloran') ); -console.log(dimacros); \ No newline at end of file +dimacros.myPlayList('Rock').addSong( + spotify.findSongByTitle('Borracho en el bar') +); + +dimacros.myPlayList('Rock').addSong( + spotify.findSongByTitle('Sentimiento Fatal') +); + +console.log( + dimacros.myPlayList('Rock') +); \ No newline at end of file From 76c3e021a59989640a03c399cc858a2f33139384 Mon Sep 17 00:00:00 2001 From: dimacros Date: Sun, 2 Jun 2019 22:33:56 -0500 Subject: [PATCH 6/7] Renombrar nombre de helper --- Retos/ejercicio-recursividad.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Retos/ejercicio-recursividad.js b/Retos/ejercicio-recursividad.js index 0eeec91..cf13687 100644 --- a/Retos/ejercicio-recursividad.js +++ b/Retos/ejercicio-recursividad.js @@ -2,18 +2,14 @@ * @author Dimacros * * Problema: - * Las parejas de numeros que sumen 8; sin usar un loop. + * Las parejas de números que sumen 8; sin usar un loop. * - * Ejemplo: [4, 6, 2, -6, 10, -2, 0, 8, 4 ...] + * Ejemplo: [3, 6, 2, -6, 10, -2, 0, 8, 4, 4] * - * return [ [ 6, 2 ], [ 10, -2 ], [ 0, 8 ] ] + * return [ [ 6, 2 ], [ 10, -2 ], [ 0, 8 ], [4, 4] ] */ -const numeros = [4, 6, 2, -6, 10, -2, 0, 8, 4]; - -const app = () => console.log( - sumPairsEquals(8, numeros) -); +const numbers = [3, 6, 2, -6, 10, -2, 0, 8, 4, 4]; function sumPairsEquals(total, numbers) { @@ -29,10 +25,10 @@ function sumPairsEquals(total, numbers) accumulator().push([a, b]); } - return sumPairsEquals(total, movePointer(numbers, 1)); + return sumPairsEquals(total, reduceLenght(numbers, 1)); } -function movePointer(numbers, length) +function reduceLenght(numbers, length) { return numbers.slice(length); } @@ -46,5 +42,6 @@ function accumulator() return accumulator.add; } -//Run application -return app(); +console.log( + sumPairsEquals(8, numbers) +); From 35f83bf378da458457fc5d5269bd76fc14829a4e Mon Sep 17 00:00:00 2001 From: dimacros Date: Sun, 2 Jun 2019 23:25:28 -0500 Subject: [PATCH 7/7] =?UTF-8?q?Corregir=20destructuraci=C3=B3n=20de=20obje?= =?UTF-8?q?to?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Retos/sesion3-reto1/app/Factories/SongFactory.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Retos/sesion3-reto1/app/Factories/SongFactory.js b/Retos/sesion3-reto1/app/Factories/SongFactory.js index 831a31c..2cb9855 100644 --- a/Retos/sesion3-reto1/app/Factories/SongFactory.js +++ b/Retos/sesion3-reto1/app/Factories/SongFactory.js @@ -4,10 +4,10 @@ const Song = require("../Song"); class SongFactory { - create({artistData, albumData, title, durationInSeconds}) + create({artist: { name: artistName}, album: { title: albumTitle}, title, durationInSeconds}) { - const artist = new Artist(artistData); - const album = new Album(albumData); + const artist = new Artist(artistName); + const album = new Album(albumTitle); return new Song(artist, album, title, durationInSeconds); }