JavaScript
TypeScript
monokai
ambiance
chaos
chrome
cloud9_day
cloud9_night
cloud9_night_low_color
clouds
clouds_midnight
cobalt
crimson_editor
dawn
dracula
dreamweaver
eclipse
github
github_dark
gob
gruvbox
gruvbox_dark_hard
gruvbox_light_hard
idle_fingers
iplastic
katzenmilch
kr_theme
kuroir
merbivore
merbivore_soft
mono_industrial
nord_dark
one_dark
pastel_on_dark
solarized_dark
solarized_light
sqlserver
terminal
textmate
tomorrow
tomorrow_night
tomorrow_night_blue
tomorrow_night_bright
tomorrow_night_eighties
twilight
vibrant_ink
xcode
上次编辑到这里,代码来自缓存 点击恢复默认模板
class Calculator {
/**
* @param {number} value
*/
constructor(value) {
}
/**
* @param {number} value
* @return {Calculator}
*/
add(value){
}
/**
* @param {number} value
* @return {Calculator}
*/
subtract(value){
}
/**
* @param {number} value
* @return {Calculator}
*/
multiply(value) {
}
/**
* @param {number} value
* @return {Calculator}
*/
divide(value) {
}
/**
* @param {number} value
* @return {Calculator}
*/
power(value) {
}
/**
* @return {number}
*/
getResult() {
}
}
运行代码
提交
typescript 解法, 执行用时: 68 ms, 内存消耗: 42.2 MB, 提交时间: 2023-06-10 19:27:14
class Calculator {
value: number
constructor(value : number) {
this.value = value
}
add(value : number) : Calculator {
this.value += value
return this
}
subtract(value : number) : Calculator {
this.value -= value
return this
}
multiply(value : number) : Calculator {
this.value *= value
return this
}
divide(value : number) : Calculator {
if (value == 0) {
throw 'Division by zero is not allowed'
}
this.value /= value
return this
}
power(value : number) : Calculator {
this.value **= value
return this
}
getResult() : number {
return this.value
}
}
javascript 解法, 执行用时: 64 ms, 内存消耗: 40.5 MB, 提交时间: 2023-06-10 19:26:20
class Calculator {
/**
* @param {number} value
*/
constructor(value) {
this.value = value;
}
/**
* @param {number} value
* @return {Calculator}
*/
add(value) {
this.value += value;
return this;
}
/**
* @param {number} value
* @return {Calculator}
*/
subtract(value) {
this.value -= value;
return this;
}
/**
* @param {number} value
* @return {Calculator}
*/
multiply(value) {
this.value *= value;
return this;
}
/**
* @param {number} value
* @return {Calculator}
*/
divide(value) {
if (!value) {
throw Error("Division by zero is not allowed");
}
this.value /= value;
return this;
}
/**
* @param {number} value
* @return {Calculator}
*/
power(value) {
this.value = Math.pow(this.value, value);
return this;
}
/**
* @return {number}
*/
getResult() {
return this.value;
}
}
javascript 解法, 执行用时: 56 ms, 内存消耗: 41.1 MB, 提交时间: 2023-06-10 19:25:18
class Calculator {
/**
* @param {number} value
*/
constructor(value) {
this.value = value;
}
/**
* @param {number} value
* @return {Calculator}
*/
add(value) {
this.value += value;
return this;
}
/**
* @param {number} value
* @return {Calculator}
*/
subtract(value) {
this.value -= value;
return this;
}
/**
* @param {number} value
* @return {Calculator}
*/
multiply(value) {
this.value *= value;
return this;
}
/**
* @param {number} value
* @return {Calculator}
*/
divide(value) {
if (!value) {
throw Error("Division by zero is not allowed");
}
this.value /= value;
return this;
}
/**
* @param {number} value
* @return {Calculator}
*/
power(value) {
this.value = this.value ** value;
return this;
}
/**
* @return {number}
*/
getResult() {
return this.value;
}
}