├── Certificate.png ├── ImageCloning.js ├── README.md └── getNumTransactions.js /Certificate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lecongaizu/Hackerrank-Javascript-Intermediate--Solution/64831fbf7afc76f212644f460c28357252047478/Certificate.png -------------------------------------------------------------------------------- /ImageCloning.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | 5 | process.stdin.resume(); 6 | process.stdin.setEncoding("ascii"); 7 | let inputString = ""; 8 | let currentLine = 0; 9 | 10 | process.stdin.on("data", function (chunk) { 11 | inputString += chunk; 12 | }); 13 | process.stdin.on("end", function () { 14 | inputString = inputString.split('\n'); 15 | main(); 16 | }); 17 | 18 | function readLine() { 19 | return inputString[currentLine++]; 20 | } 21 | class Size { 22 | constructor(width, height) { 23 | this.width = width; 24 | this.height = height; 25 | } 26 | } 27 | 28 | class Image { 29 | // Add methods here 30 | url; 31 | height; 32 | width; 33 | constructor(url, size){ 34 | this.url = url; 35 | this.height = size.height; 36 | this.width = size.width 37 | console.log(size) 38 | } 39 | getUrl(){ 40 | return this.url; 41 | } 42 | setUrl(url){ 43 | this.url = url; 44 | } 45 | setSize(width,height) { 46 | this.width = width; 47 | this.height = height; 48 | } 49 | getSize(){ 50 | return new Size(this.width, this.height) 51 | } 52 | cloneImage(){ 53 | return new Image(this.url, new Size(this.width, this.height)) 54 | } 55 | } 56 | 57 | 58 | function main() { 59 | const ws = fs.createWriteStream(process.env.OUTPUT_PATH); 60 | 61 | let images = []; 62 | 63 | let numberOfImages = parseInt(readLine().trim()); 64 | 65 | while (numberOfImages-- > 0) { 66 | let inputs = readLine().trim().split(' '); 67 | images.push(new Image(inputs[0], new Size(parseInt(inputs[1]), parseInt(inputs[2])))); 68 | } 69 | 70 | let numberOfOperations = parseInt(readLine().trim()); 71 | while (numberOfOperations-- > 0) { 72 | let inputs = readLine().trim().split(' '); 73 | const image = images[parseInt(inputs[1]) - 1]; 74 | const operation = inputs[0]; 75 | 76 | switch(operation) { 77 | case 'Clone': 78 | images.push(image.cloneImage()); 79 | break; 80 | case 'UpdateUrl': 81 | image.setUrl(inputs[2]); 82 | break; 83 | case 'UpdateSize': 84 | image.setSize(parseInt(inputs[2]), parseInt(inputs[3])); 85 | break; 86 | default: 87 | break; 88 | } 89 | } 90 | 91 | images.forEach((img) => { 92 | const size = img.getSize(); 93 | ws.write(`${img.getUrl()} ${size.width} ${size.height}\n`); 94 | }) 95 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hackerrank-Javascript-Intermediate--Solution 2 | Hackerrank-Javascript(Intermediate)-Solution 3 | -------------------------------------------------------------------------------- /getNumTransactions.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const https = require('https'); 5 | 6 | process.stdin.resume(); 7 | process.stdin.setEncoding('utf-8'); 8 | 9 | let inputString = ''; 10 | let currentLine = 0; 11 | 12 | process.stdin.on('data', function(inputStdin) { 13 | inputString += inputStdin; 14 | }); 15 | 16 | process.stdin.on('end', function() { 17 | inputString = inputString.split('\n'); 18 | main(); 19 | }); 20 | 21 | function readLine() { 22 | return inputString[currentLine++]; 23 | } 24 | 25 | const axios = require('axios'); 26 | 27 | async function getNumTransactions(username) { 28 | // write your code here 29 | // API endpoint: https://jsonmock.hackerrank.com/api/article_users?username= 30 | // API endpoint: https://jsonmock.hackerrank.com/api/transactions?&userId= 31 | try { 32 | const {data} = await axios.get(`https://jsonmock.hackerrank.com/api/article_users?username=${username}`); 33 | if(data.data && data.data.length !==0){ 34 | const userID = data.data[0].id; 35 | const response = await axios.get(`https://jsonmock.hackerrank.com/api/transactions?&userId=${userID}`) 36 | return response.data.total; 37 | } else { 38 | return "Username Not Found"; 39 | } 40 | } catch (error){ 41 | console.log(error); 42 | } 43 | } 44 | async function main() { 45 | const ws = fs.createWriteStream(process.env.OUTPUT_PATH); 46 | const username = readLine().trim(); 47 | const result = await getNumTransactions(username); 48 | ws.write(result.toString()); 49 | }'use strict'; 50 | 51 | const fs = require('fs'); 52 | const https = require('https'); 53 | 54 | process.stdin.resume(); 55 | process.stdin.setEncoding('utf-8'); 56 | 57 | let inputString = ''; 58 | let currentLine = 0; 59 | 60 | process.stdin.on('data', function(inputStdin) { 61 | inputString += inputStdin; 62 | }); 63 | 64 | process.stdin.on('end', function() { 65 | inputString = inputString.split('\n'); 66 | main(); 67 | }); 68 | 69 | function readLine() { 70 | return inputString[currentLine++]; 71 | } 72 | 73 | const axios = require('axios'); 74 | 75 | async function getNumTransactions(username) { 76 | // write your code here 77 | // API endpoint: https://jsonmock.hackerrank.com/api/article_users?username= 78 | // API endpoint: https://jsonmock.hackerrank.com/api/transactions?&userId= 79 | try { 80 | const {data} = await axios.get(`https://jsonmock.hackerrank.com/api/article_users?username=${username}`); 81 | if(data.data && data.data.length !==0){ 82 | const userID = data.data[0].id; 83 | const response = await axios.get(`https://jsonmock.hackerrank.com/api/transactions?&userId=${userID}`) 84 | return response.data.total; 85 | } else { 86 | return "Username Not Found"; 87 | } 88 | } catch (error){ 89 | console.log(error); 90 | } 91 | } 92 | async function main() { 93 | const ws = fs.createWriteStream(process.env.OUTPUT_PATH); 94 | const username = readLine().trim(); 95 | const result = await getNumTransactions(username); 96 | ws.write(result.toString()); 97 | } --------------------------------------------------------------------------------