DESCRIPTION

Given an integral number, determine if it’s a square number:

In mathematics, a square number or perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself.

The tests will always use some integral number, so don’t worry about that in dynamic typed languages.

Examples

1
2
3
4
5
6
-1  =>  false
0 => true
3 => false
4 => true
25 => true
26 => false

SOLUTION

  • 方法一:
1
2
3
4
5
6
var isSquare = function (n) {
// 求平方根并取整
let roundSqrt = Math.round(Math.sqrt(n));
// 判断平方根相乘的结果是否与传入的数值相等
return n === roundSqrt * roundSqrt;
};
阅读全文 »


DESCRIPTION

In this kata you will create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out.

Example

1
2
3
filter_list([1, 2, "a", "b"]) == [1, 2];
filter_list([1, "a", "b", 0, 15]) == [1, 0, 15];
filter_list([1, 2, "aasf", "1", "123", 123]) == [1, 2, 123];

SOLUTION

  • 数组的 filter() 方法
1
2
3
4
function filter_list(l) {
// Return a new array with the strings filtered out
return l.filter((word) => typeof word === "number");
}
阅读全文 »


DESCRIPTION

Trolls are attacking your comment section!

A common way to deal with this situation is to remove all of the vowels from the trolls’ comments, neutralizing the threat.

Your task is to write a function that takes a string and return a new string with all vowels removed.

For example, the string “This website is for losers LOL!” would become “Ths wbst s fr lsrs LL!”.

Note: for this kata y isn’t considered a vowel.

SOLUTION

  • 方法一:字符串的 replace()replaceAll() 方法都可,这两个方法都是返回一个新的字符串。

replace() 字符串模式只会被替换一次。要执行全局搜索和替换,请使用带有 g 标志的正则表达式或使用 replaceAll()。

1
2
3
4
5
6
function disemvowel(str) {
let regex = /aeiou/gi;
let result = str.replace(regex, "");
// let result = str.replaceAll(regex, "");
return result;
}
阅读全文 »


for…in 语句以任意顺序迭代一个对象的除 Symbol 以外的可枚举属性,包括继承的可枚举属性。

语法

1
2
3
4
5
for (variable in object) {
if(object.hasOwnProperty(variable) {
...
}
}

variable 在每次迭代时,variable 会被赋值为不同的属性名。

object 非 Symbol 类型的可枚举属性被迭代的对象。

阅读全文 »


分析原因应该是点击切换标签页时,组件没有销毁。 解决办法:给组件添加 v-if 判断,使组件真正的创建和销毁。然后就在组件中定义的 mounteddestoryed 钩子函数就可以被正常调用了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<template>
<div class="app-container">
<el-tabs v-model="activeName" @tab-click="handleClick" type="border-card">
<!--实时状态-->
<el-tab-pane name="realTimeState">
<span slot="label"> <i class="el-icon-time"></i> 实时状态</span>
<realTimeState v-if="activeName === 'realTimeState'" />
</el-tab-pane>
<!--历史状态-->
<el-tab-pane name="historyData">
<span slot="label"> <i class="el-icon-document"></i> 历史状态</span>
<historyData v-if="activeName === 'historyData'" />
</el-tab-pane>
<!--基本信息-->
<el-tab-pane name="basicInfo">
<span slot="label"> <i class="el-icon-info"></i> 基本信息</span>
<basicInfo v-if="activeName === 'basicInfo'" />
</el-tab-pane>
<!--状态导出-->
<el-tab-pane name="exportData">
<span slot="label"> <i class="el-icon-download"></i> 状态导出</span>
<exportData v-if="activeName === 'exportData'" />
</el-tab-pane>
<!--故障查询-->
<el-tab-pane name="error">
<span slot="label"> <i class="el-icon-error"></i> 故障查询</span>
<error v-if="activeName === 'error'" />
</el-tab-pane>
<!--预警监测-->
<el-tab-pane name="statusPicture">
<span slot="label"> <i class="el-icon-picture"></i> 预警监测</span>
<statusPicture v-if="activeName === 'statusPicture'" />
</el-tab-pane>
</el-tabs>
</div>
</template>

阅读全文 »
0%