This JavaScript code is designed to handle a series of operations on images. It allows the creation of images with specific URLs and sizes, and also provides functionality to clone and modify these images. The modifications can be done on both the URL and the size of the images.
CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷
The solution works by defining two classes, Size and Image. The Size class is used to encapsulate the width and height of an image, while the Image class encapsulates the URL and size of an image, and provides methods for getting and setting these properties. The main function reads a series of operations from the input, and performs these operations on the images. The operations include cloning an image, updating the URL of an image, and updating the size of an image. The results of these operations are then written to an output stream.
use strict';
const fs = require('fs');
process.stdin.resume();
process.stdin.setEncoding('ascii');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', function (chunk) {
inputString += chunk;
});
process.stdin.on('end', function () {
inputString = inputString.split('\n');
main();
});
function readLine() {
return inputString[currentLine++];
}
class Size {
constructor(width, height) {
this.width = width;
this.height = height;
}
}
class Image {
url;
height;
width;
constructor(url, size){
this.url = url;
this.height = size.height;
this.width = size.width
console.log(size)
}
getUrl(){
return this.url;
}
setUrl(url){
this.url = url;
}
setSize(width,height) {
this.width = width;
this.height = height;
}
getSize(){
return new Size(this.width, this.height)
}
cloneImage(){
return new Image(this.url, new Size(this.width, this.height))
}
}
function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
let images = [];
let numberOfImages = parseInt(readLine().trim());
while (numberOfImages-- > 0) {
let inputs = readLine().trim().split(' ');
images.push(new Image(inputs[0], new Size(parseInt(inputs[1]), parseInt(inputs[2]))));
}
let numberOfOperations = parseInt(readLine().trim());
while (numberOfOperations-- > 0) {
let inputs = readLine().trim().split(' ');
const image = images[parseInt(inputs[1]) - 1];
const operation = inputs[0];
switch(operation) {
case 'Clone':
images.push(image.cloneImage());
break;
case 'UpdateUrl':
image.setUrl(inputs[2]);
break;
case 'UpdateSize':
image.setSize(parseInt(inputs[2]), parseInt(inputs[3]));
break;
default:
break;
}
}
images.forEach((img) => {
const size = img.getSize();
ws.write(`${img.getUrl()} ${size.width} ${size.height}\n`);
})
}
If you have a HackerRank Certification test or a coding interview coming up, you can use CodeRankGPT to your advantage. It will assist you during your test and help ensure you get the certification or the job.
AI is here now, and other candidates might be using it to get ahead and win the job. 🧐
The form has been successfully submitted.