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..a2426a2 --- /dev/null +++ b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/Spotify.js @@ -0,0 +1,31 @@ +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(element => element.name === albumName) || null; + } + 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/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..5c4521d --- /dev/null +++ b/Retos/sesion3-reto1/sesion3-reto1-RaulRondon/index.js @@ -0,0 +1,88 @@ +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.addAlbum(album); +spotify.addAlbum(album3); +spotify.addUser(user_premium); + + +console.log(spotify); + +spotify.deleteAlbum(album.name); +spotify.deleteUser(user_premium.username); +spotify.deleteUser(user.username); +console.log(spotify); 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); + } +}; 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));