From 98f297fc263d0c955270f486602bb0140c010692 Mon Sep 17 00:00:00 2001 From: Raul Rondon Date: Thu, 30 May 2019 20:38:26 -0500 Subject: [PATCH 1/3] Agregando reto 1 --- reto1.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 reto1.js diff --git a/reto1.js b/reto1.js new file mode 100644 index 0000000..4a8a59b --- /dev/null +++ b/reto1.js @@ -0,0 +1,26 @@ +const numbers = [2,5,4,6,10,4,0,-8,8,16]; +let numbers_size = numbers.length; +let hashmap = {}; +let answer = []; +const n = 8; + +function recursionOn(tam) { + + let target = n - numbers[tam-1]; + + if (tam<=0) + return answer; + + if(!hashmap[target]) + { + hashmap[numbers[tam-1]] = 1; + } + + else{ + let array = [numbers[tam-1],target]; + answer.push(array); + } + return (recursionOn(tam-1)) +} + +console.log(recursionOn(numbers_size)); From a4c865942a2c77134d66de3d066fc29cff69a7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Rondon?= Date: Mon, 3 Jun 2019 17:03:38 -0500 Subject: [PATCH 2/3] Agregando cambios en estructura --- .idea/Serverless-Training.iml | 9 + .idea/misc.xml | 22 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 859 ++++++++++++++++++ .../sesion3-reto1-RaulRondon/Album.js | 41 + .../sesion3-reto1-RaulRondon/Author.js | 9 + .../sesion3-reto1-RaulRondon/Song.js | 12 + .../sesion3-reto1-RaulRondon/Spotify.js | 23 + .../sesion3-reto1-RaulRondon/User.js | 9 + .../sesion3-reto1-RaulRondon/index.js | 84 ++ .../sesion3-reto1-RaulRondon/objectFactory.js | 11 + 12 files changed, 1093 insertions(+) create mode 100644 .idea/Serverless-Training.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Album.js create mode 100644 Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Author.js create mode 100644 Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Song.js create mode 100644 Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Spotify.js create mode 100644 Retos/sesion3-reto1/sesion3-reto1-RaulRondon/User.js create mode 100644 Retos/sesion3-reto1/sesion3-reto1-RaulRondon/index.js create mode 100644 Retos/sesion3-reto1/sesion3-reto1-RaulRondon/objectFactory.js diff --git a/.idea/Serverless-Training.iml b/.idea/Serverless-Training.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Serverless-Training.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5a210c3 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,22 @@ + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f821e27 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..41e6031 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,859 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + true + + + + DIRECTORY + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1559591495642 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Album.js b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Album.js new file mode 100644 index 0000000..bb43d2b --- /dev/null +++ b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Album.js @@ -0,0 +1,41 @@ +const Song = require ("./Song"); + +module.exports = class Album { + getNumberOfLikes(){ + let number = 0; + for (let s in this.song) + { + number+=this.song[s].like_number; + } + + return number; + } + addSong(song){ + this.song.push(song); + this.like_number = this.getNumberOfLikes(); + } + deleteSong(song){ + let index = this.song.indexOf(song); + this.song.splice(index,1); + this.like_number = this.getNumberOfLikes(); + } + addAuthor(author){ + this.author.push(author); + } + deleteAuthor(author){ + let index = this.song.indexOf(author); + this.author.splice(index,1); + } + constructor({name, author,time, genre, dislike_number, image, upload_date, song}) { + this.name = name; + this.author = Array.from(author); + this.time = time; + this.genre = genre; + this.song = Array.from(song); + this.like_number = this.getNumberOfLikes(); + this.dislike_number = dislike_number; + this.image = image; + this.upload_date = upload_date; + + } +}; diff --git a/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Author.js b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Author.js new file mode 100644 index 0000000..d46a224 --- /dev/null +++ b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Author.js @@ -0,0 +1,9 @@ +module.exports = class Author { + constructor({name, country, biography, listeners, followers}) { + this.name = name; + this.country = country; + this.biography = biography; + this.listeners = listeners; + this.followers = followers; + } +}; diff --git a/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Song.js b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Song.js new file mode 100644 index 0000000..e0f1c11 --- /dev/null +++ b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Song.js @@ -0,0 +1,12 @@ +module.exports = class Song { + constructor({title, album, time, genre, like_number, dislike_number, image, upload_date}) { + this.title = title; + this.album = album; + this.time = time; + this.genre = genre; + this.like_number = like_number; + this.dislike_number = dislike_number; + this.image = image; + this.upload_date = upload_date; + } +}; diff --git a/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Spotify.js b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Spotify.js new file mode 100644 index 0000000..3be1824 --- /dev/null +++ b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Spotify.js @@ -0,0 +1,23 @@ +module.exports = class Spotify { + constructor(album, user) { + this.album = Array.from(album); + this.user = Array.from(user); + } + addAlbum(newAlbum) { + if(this.album.indexOf(newAlbum) === -1) + this.album.push(newAlbum); + } + getAlbum(albumName) { + return this.album.find(elemento => elemento.name === albumName) || null; + } + deleteAlbum(album) { + let index = this.album.indexOf(album); + if(this.album.indexOf(album) !== -1) + this.album.splice(index,1); + } + addUser(newUser) { + let exist = this.user.find(elemento=>elemento.username === newUser.username); + if(!exist) + this.user.push(newUser); + } +}; diff --git a/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/User.js b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/User.js new file mode 100644 index 0000000..2cefd5b --- /dev/null +++ b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/User.js @@ -0,0 +1,9 @@ +module.exports = class User { + constructor(username,password,email,name,premium) { + this.username = username; + this.password = password; + this.email = email; + this.name = name; + this.premium = premium || false; + } +}; diff --git a/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/index.js b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/index.js new file mode 100644 index 0000000..7659fb3 --- /dev/null +++ b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/index.js @@ -0,0 +1,84 @@ +const objectFactory = require("./objectFactory"); +const User = require("./User"); +const Spotify = require("./Spotify"); + +const author = objectFactory.createObject("Author", { + name: "Raul Rondon", + country: "Peru", + biography: "Peruano de nacimiento", + listeners: 100, + followers: 100 +}); + +const author2 = objectFactory.createObject("Author", { + name: "Juan Perez", + country: "Peru", + biography: "Peruano de nacimiento", + listeners: 12, + followers: 12 +}); + +const song = objectFactory.createObject("Song", { + title: "Rock yourself", + album: "Peruana", + time: 100, + genre: "Rock", + like_number: 1000, + dislike_number: 10, + image: "http://url.com", + upload_date: "2019-05-05", + country: "Peru", + biography: "Peruano de nacimiento", + listeners: 100, + followers: 100 +}); + +const song2 = objectFactory.createObject("Song", { + title: "Rock yourselfs", + album: "Peruanas", + time: 100, + genre: "Rock", + like_number: 100, + dislike_number: 10, + image: "http://url.com", + upload_date: "2019-05-05", + country: "Peru", + biography: "Peruano de nacimiento", + listeners: 100, + followers: 100 +}); + +const album = objectFactory.createObject("Album", { + name: "Tu mano", + author: [author], + time: 100, + genre: "Rock", + like_number: 1000, + dislike_number: 100, + image: "https://image.com", + upload_date: '2019-05-05', + song: [song] +}); + +const album3 = objectFactory.createObject("Album", { + name: "Como mirarte", + author: [author], + genre: "Salsa", + image: "https://image.com", + upload_date: '2019-05-05', + song: [song] +}); + +const user = new User("rrondon","1234","rrondon@gmail.com","Raul Rondon Ponce"); +const user_premium = new User("jperez","1234","jperez@gmail.com","Juan Perez"); + +const spotify = new Spotify([album],[user,user_premium]); +let album1 = spotify.getAlbum("Como mirarte"); +spotify.addUser(user_premium); +spotify.addUser(user_premium); + +console.log(album1); + +console.log(spotify); + +//console.log(album); diff --git a/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/objectFactory.js b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/objectFactory.js new file mode 100644 index 0000000..5748e71 --- /dev/null +++ b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/objectFactory.js @@ -0,0 +1,11 @@ +const Author = require ("./Author"); +const Album = require ("./Album"); +const Song = require ("./Song"); +const object = {Author,Album,Song} + +module.exports = { + createObject(type, attributes) { + const objectType = object[type]; + return new objectType(attributes); + } +}; From f17577bc99a80d8a8b951b87f21081f25c313837 Mon Sep 17 00:00:00 2001 From: Raul Rondon Date: Mon, 3 Jun 2019 19:38:27 -0500 Subject: [PATCH 3/3] Agregando cambios de crud de album y user --- .../sesion3-reto1-RaulRondon/Spotify.js | 18 +++++++++++++----- .../sesion3-reto1-RaulRondon/index.js | 12 ++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Spotify.js b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Spotify.js index 3be1824..a2426a2 100644 --- a/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Spotify.js +++ b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Spotify.js @@ -8,16 +8,24 @@ module.exports = class Spotify { this.album.push(newAlbum); } getAlbum(albumName) { - return this.album.find(elemento => elemento.name === albumName) || null; + return this.album.find(element => element.name === albumName) || null; } - deleteAlbum(album) { - let index = this.album.indexOf(album); - if(this.album.indexOf(album) !== -1) - this.album.splice(index,1); + deleteAlbum(albumName) { + let album = this.getAlbum(albumName); + if(album!==null) + this.album.splice(this.album.indexOf(album),1); } addUser(newUser) { let exist = this.user.find(elemento=>elemento.username === newUser.username); if(!exist) this.user.push(newUser); } + getUser(username) { + return this.user.find(element => element.username === username) || null; + } + deleteUser(username) { + let user = this.getUser(username); + if(user!==null) + this.user.splice(this.user.indexOf(user),1); + } }; diff --git a/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/index.js b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/index.js index 7659fb3..5c4521d 100644 --- a/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/index.js +++ b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/index.js @@ -73,12 +73,16 @@ const user = new User("rrondon","1234","rrondon@gmail.com","Raul Rondon Ponce"); const user_premium = new User("jperez","1234","jperez@gmail.com","Juan Perez"); const spotify = new Spotify([album],[user,user_premium]); -let album1 = spotify.getAlbum("Como mirarte"); -spotify.addUser(user_premium); +//let album1 = spotify.getAlbum("Como mirarte"); + +spotify.addAlbum(album); +spotify.addAlbum(album3); spotify.addUser(user_premium); -console.log(album1); console.log(spotify); -//console.log(album); +spotify.deleteAlbum(album.name); +spotify.deleteUser(user_premium.username); +spotify.deleteUser(user.username); +console.log(spotify);