This file contains 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
//Requiring Express in the file | |
const express = require("express"); | |
const app = express(); //This is our Express Applicaiton | |
//We shall now define a simple route to display "Hello World" | |
app.get("/",function(req,res){ | |
res.send("Hello World"); | |
}); |
This file contains 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
// Declaring a variable adventure, which has a type of string array | |
const adventure: Array<string> = [ | |
"India", | |
"USA", | |
"Canada", | |
"Japan", | |
"South Africa", | |
]; | |
/** |
This file contains 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
export namespace DigitsInNumber { | |
// Check if value is a number | |
const isNumber = (value: any): boolean => { | |
return !isNaN(value); | |
}; | |
// Count the digits in the number | |
export const countDigits = (value: any): string => { | |
if (isNumber(value) === false) return "Hey, we need a number!"; | |
if (value < 0) return "We'll ignore negative numbers"; |
This file contains 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
import {DigitsInNumber} from "./digitsInNumber" | |
console.log(DigitsInNumber.countDigits(100)); // Double Digit | |
console.log(DigitsInNumber.countDigits("one hundred")); // Hey, we need a number! | |
console.log(DigitsInNumber.countDigits(-100)); // We'll ignore negative numbers |
This file contains 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
/** | |
* Allow only positive numbers, throw error for negative ones | |
* @param {number} num - Number to test | |
*/ | |
export const asyncThrowsError = async (num: number) => { | |
if (num >= 0) return "You are good to go"; | |
throw Error("Negative numbers are not accepted"); | |
}; |
This file contains 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
/** | |
* Allow only positive numbers, throw error for negative ones | |
* @param {number} num - Number to test | |
*/ | |
export const checkNumber = async (num: number) => { | |
if (num >= 0) return "You are good to go"; | |
throw Error("Negative numbers are not accepted"); | |
}; |
This file contains 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
import { checkNumber } from "../checkNumber"; | |
import * as chai from "chai"; | |
const expect = chai.expect; | |
/** | |
* Takes in a function and checks for error | |
* @param {Function} method - The function to check | |
* @param {any[]} params - The array of function parameters | |
* @param {string} message - Optional message to match with error message |
This file contains 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
/** | |
* SumOfNumbers - To find the sum of all the numbers passed as command line | |
* input | |
*/ | |
public class SumOfNumbers { | |
public static void main(String[] args) { | |
int len = args.length; // Length of the array args | |
int sum = 0; // Variable to hold our result | |
for (int i = 0; i < len; i++) |
This file contains 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 spawn = require("child_process").spawn; | |
function sumOfNumbers(numbers) { | |
let args = []; | |
args.push("SumOfNumbers"); // Making our Java filename as the first argument to be picked by the java command | |
// Push the numbers as the other arguments | |
numbers.forEach((element) => { | |
args.push(element); | |
}); |
This file contains 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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
contract SolidityTest { | |
uint public multiplier; | |
uint internal iMultiplier; | |
constructor() { | |
multiplier = 10; | |
iMultiplier = 100; | |
} |