Skip to content

Instantly share code, notes, and snippets.

View suhailgupta03's full-sized avatar
:octocat:

Suhail Gupta suhailgupta03

:octocat:
View GitHub Profile
var x = prompt("Input x")
var y = prompt("Input y")
function calculator(x, y) {
x = parseInt(x); // convert string to int
y = parseInt(y); // convert string to int
function add() {
return x + y;
}
function calculator(x, y) {
function add() {
return x + y;
}
function subtract() {
return x - y;
}
function multiply() {
// Define a string variable
const sampleText = "Hello, World! Welcome to JavaScript.";
// Use the split function to convert the string into an array
// The space character ' ' is used as the separator
const wordsArray = sampleText.split(' ');
// Log the original string
console.log("Original string:", sampleText);
const stripe = require('stripe')('YOUR_STRIPE_SECRET_KEY');
async function handlePaymentMethodRequired(paymentIntentId) {
try {
const paymentIntent = await stripe.paymentIntents.retrieve(paymentIntentId);
if (paymentIntent.status === 'requires_payment_method') {
// Prompt the user to provide a new payment method
// For example, collect new payment details from the user and create a PaymentMethod
// Assuming you have a new PaymentMethod ID from the frontend
const stripe = require('stripe')('YOUR_STRIPE_SECRET_KEY');
async function handlePaymentMethodRequired(paymentIntentId) {
try {
const paymentIntent = await stripe.paymentIntents.retrieve(paymentIntentId);
if (paymentIntent.status === 'requires_payment_method') {
// Prompt the user to provide a new payment method
// For example, collect new payment details from the user and create a PaymentMethod
// Assuming you have a new PaymentMethod ID from the frontend
/**
* Dependency Inversion Principle (DIP):
* High-level modules should not depend directly on low-level modules,
* but both should depend on abstractions. Additionally, these abstractions
* should not depend on details; rather, details should depend on abstractions.
*/
// Bad: High-level module depends on the low-level module's details.
class EmailClient {
sendEmail() {
/**
* Interface Segregation Principle (ISP): Clients should not be forced to
* depend on interfaces they do not use.
*/
class Animal {
eat(){}
}
class FlyingAnimal extends Animal {
fly(){
/**
* Liskov Substitution Principle (LSP): Objects of a superclass should be
* replaceable with objects of a subclass without affecting the
* correctness of the program.
*/
class Bird {
fly() {
console.log('I can fly');
}
}
/**
* Open/Closed Principle (OCP): Software entities should be open
* for extension but closed for modification.
*/
class AreaCalculator { // BAD CODE
calculate(shape) {
if (shape instanceof Square) {
return shape.width * shape.width;
}else if(shape instanceof Circle) {
return Math.PI * shape.radius * shape.radius;
// SINGLE RESPONSIBILITY PRINCIPLE
class User {
constructor(name) {
this.name = name;
}
getName() {
return this.name;
}