Skip to content

Instantly share code, notes, and snippets.

@adarsh-chakraborty
Created May 28, 2022 11:08
Show Gist options
  • Save adarsh-chakraborty/f5821bdb28d18db756c7c254ed3f030c to your computer and use it in GitHub Desktop.
Save adarsh-chakraborty/f5821bdb28d18db756c7c254ed3f030c to your computer and use it in GitHub Desktop.

Assignment #1

Node.js JSON Cleaning In the JavaScript file, write a program to perform a GET request on the route https://coderbyte.com/api/challenges/json/json-cleaning and then clean the object according to the following rules: Remove all keys that have values of N/A, -, or empty strings. If one of these values appear in an array, remove that single item from the array. Then console log the modified object as a string.

Example Input {"name":{"first":"Daniel","middle":"N/A","last":"Smith"},"age":45}

Example Output {"name":{"first":"Daniel","last":"Smith"},"age":45}

My solution:

const axios = require('axios').default;

let data;


(async () => {

let result = await axios.get('https://coderbyte.com/api/challenges/json/json-cleaning');
data = result.data;
console.log("Data:",data);
cObj(data);
console.log(data);
})();


function cObj(obj){

 if(Array.isArray(obj)){
   obj = obj.filter(value => value != '-');
  return obj;
   
 }
  for(let key in obj){
    if(!obj[key] ||obj[key] === 'N/A' || obj[key] === '-'){
      
      delete obj[key];
    }
    if(typeof obj[key] === 'object' ){
     obj[key] = cObj(obj[key]);
    }
  }
  return obj;
}

Assignemnt #2

Star Rating Have the function StarRating(str) take the str parameter being passed which will be an average rating between 0.00 and 5.00, and convert this rating into a list of 5 image names to be displayed in a user interface to represent the rating as a list of stars and half stars. Ratings should be rounded to the nearest half. There are 3 image file names available: "full.jpg", "half.jpg", "empty.jpg". The output will be the name of the 5 images (without the extension), from left to right, separated by spaces. For example: if str is "2.36" then this should be displayed by the following image: https://i.imgur.com/KHUFpWZ.jpg

So your program should return the string "full full half empty empty". Examples

Input: "0.38"
Output: half empty empty empty empty
Input: "4.5"
Output: full full full full half

Assignment 3

SQL Vendor Join

Your table: maintable_2IYIE

MySQL version: 8.0.23 In this MySQL challenge, your query should return the vendor information along with the values from the table cb_vendorinformation. You should combine the values of the two tables based on the GroupID column. The final query should only print out the GroupID, CompanyName, and final count of all rows that are grouped into each company name under a column titled Count. The output table should be then sorted by the Count column and then sorted by GroupID so that a higher number appears first.

Your output should look like the https://coderbytestaticimages.s3.amazonaws.com/editor/challenges/ascii_vendor_join.png


Assesment 4

In this MySQL challenge, the table provided shows all new users signing up on a specific date in the format YYYY-MM-DD. Your query should output the change from one month to the next. Because the first month has no preceding month, your output should skip that row. Your output should look like the following table. https://coderbytestaticimages.s3.amazonaws.com/editor/challenges/ascii_user_logins.png


Assesment 5

Swap Case Have the function SwapCase(str) take the str parameter and swap the case of each character. For example: if str is "Hello World" the output should be hELLO wORLD. Let numbers and symbols stay the way they are. Examples

Input: "Hello-LOL"
Output: hELLO-lol
Input: "Sup DUDE!!?"
Output: sUP dude!!? 

My solution:

function SwapCase(str) { 

  const result = str.split('').map(letter => letter === letter.toUpperCase() ? letter.toLowerCase() : letter.toUpperCase());
  return result.join('');
   

}
   
// keep this function call here 
console.log(SwapCase(readline()));

Assesment 6

Array Addition Have the function ArrayAddition(arr) take the array of numbers stored in arr and return the string true if any combination of numbers in the array (excluding the largest number) can be added up to equal the largest number in the array, otherwise return the string false. For example: if arr contains [4, 6, 23, 10, 1, 3] the output should return true because 4 + 6 + 10 + 3 = 23. The array will not be empty, will not contain all the same elements, and may contain negative numbers. Examples

Input: [5,7,16,1,2]
Output: false
Input: [3,5,-1,8,12]
Output: true 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment