Skip to content

Instantly share code, notes, and snippets.

View ruddha2001's full-sized avatar
🎯
Learning

Aniruddha Chatterjee ruddha2001

🎯
Learning
View GitHub Profile
@ruddha2001
ruddha2001 / contracts...SolidityTest.sol
Created October 25, 2022 20:11
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SolidityTest {
uint public multiplier;
uint internal iMultiplier;
constructor() {
multiplier = 10;
iMultiplier = 100;
}
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);
});
/**
* 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++)
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
/**
* 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");
};
/**
* 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");
};
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
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";
// Declaring a variable adventure, which has a type of string array
const adventure: Array<string> = [
"India",
"USA",
"Canada",
"Japan",
"South Africa",
];
/**
//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");
});