Skip to content

Instantly share code, notes, and snippets.

View ericcchiu's full-sized avatar

Eric Chiu ericcchiu

  • The Home Depot
  • Austin, Texas
View GitHub Profile
const getHttpStatusCode = statusCode => clientResponseCodeMap.get(statusCode) ?? clientResponseCodeMap.get(500);
// Object
const clientResponseCode = {
400: 'Bad Request: The server could not understand the request due to invalid syntax.',
401: 'Unauthorized: The client is unauthenticated and must be properly authenticated.',
403: 'Forbidden: The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource.',
404: 'Not Found: The server can not find the requested resource.',
500: 'Internal Server Error: The server has encountered a situation it does not know how to handle.',
};
// Map
const clientResponseCodeMap = new Map([
// Status Code Table
const clientResponseCode = {
400: 'Bad Request: The server could not understand the request due to invalid syntax.',
401: 'Unauthorized: The client is unauthenticated and must be properly authenticated.',
403: 'Forbidden: The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource.',
404: 'Not Found: The server can not find the requested resource.',
500: 'Internal Server Error: The server has encountered a situation it does not know how to handle.',
};
// getHttpStatusCode function that returns the message response associated with that status code.
// Client Response Code Object
const clientResponseCode = {
400: 'Bad Request: The server could not understand the request due to invalid syntax.',
401: 'Unauthorized: The client is unauthenticated and must be properly authenticated.',
403: 'Forbidden: The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource.',
404: 'Not Found: The server can not find the requested resource.',
500: 'Internal Server Error: The server has encountered a situation it does not know how to handle.',
};
// Switch Statement: Client Response Codes
switch (httpStatusCode) {
case 400:
statusCodeResponse = `${httpStatusCode} Bad Request: The server could not understand the request due to invalid syntax.`;
break;
case 401:
statusCodeResponse = `${httpStatusCode} Unauthorized: The client is unauthenticated and must be properly authenticated.`;
break;
case 403:
statusCodeResponse = `${httpStatusCode} Forbidden: The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource.`;
let lightColor = 'Green';
switch (lightColor) {
case 'Red':
console.log('Stop');
break;
case 'Yellow':
console.log('Slow');
break;
case 'Green':
console.log('Go');
if (num % 15 === 0) {
console.log('FizzBuzz');
} else if (num % 3 === 0) {
console.log('Fizz');
} else if (num % 5 === 0) {
console.log('Buzz');
} else {
console.log(num);
}
if (num % 2 === 0) {
console.log('TRUE');
}
console.log('FALSE');
const nums = [1,2,3,4,5];
const isEven = num => {
if(num % 2 === 0) return num;
};
const isOdd = num => {
if(num & 2 !== 0) return num;
}
@ericcchiu
ericcchiu / DeepFreezeRecursiveAlgorithm.js
Created October 22, 2021 01:58
DeepFreezeObjectRecursive
const sampleObject = {
author: "J.R.R. Tolkien",
genre: "Sci-Fi/Fantasy",
birthday: "January 3, 1892",
books: [
{
title: "The Silmarillion",
publicationDate: 1927
},
{