This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Keep { | |
constructor(line) { | |
this.type = 'Keep'; | |
this.line = line; | |
} | |
} | |
class Insert { | |
constructor(line) { | |
this.type = 'Insert'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculator(x, y) { | |
function add() { | |
return x + y; | |
} | |
function subtract() { | |
return x - y; | |
} | |
function multiply() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; |
NewerOlder