[8 kyu] Correct the mistakes of the character recognition software
Character recognition software is widely used to digitise printed texts. Thus the texts can be edited, searched and stored on a computer.
When documents (especially pretty old ones written with a typewriter), are digitised character recognition softwares often make mistakes.
Your task is correct the errors in the digitised text. You only have to handle the following mistakes:
S is misinterpreted as 5
O is misinterpreted as 0
I is misinterpreted as 1
The test cases contain numbers only by mistake.
翻译:
字符识别软件被广泛用于印刷文本的数字化。因此,文本可以在计算机上编辑、搜索和存储。
当文件(特别是用打字机写的相当旧的文件)被数字化时,字符识别软件常常会出错。
你的任务是纠正数字化文本中的错误。您只需处理以下错误:
S被误解为5
O被误解为0
i被误解为1
测试用例只包含错误的数字。
解:
function correct(string) {
return string.replace(/0/g, "O")
.replace(/5/g, "S")
.replace(/1/g, "I");
}
[8 kyu] Find out whether the shape is a cube
To find the volume (centimeters cubed) of a cuboid you use the formula:
volume = Length * Width * Height
But someone forgot to use proper record keeping, so we only have the volume, and the length of a single side!
It's up to you to find out whether the cuboid has equal sides (= is a cube).
Return true if the cuboid could have equal sides, return false otherwise.
Return false for invalid numbers too (e.g volume or side is less than or equal to 0).
Note: the sides must be integers
翻译:
要找到长方体的体积(厘米立方),可以使用以下公式:
体积=长度宽度高度
但是有人忘了使用正确的记录,所以我们只有体积和单边长度!
这个长方体是否有等边取决于你。
如果长方体可以有相等的边,则返回true,否则返回false。
对于无效数字也返回false(例如,体积或边小于或等于0)。
注意:边必须是整数
解:
var cubeChecker = function(volume, side){
return Math.pow(side, 3) === volume && side > 0;
};
[7 kyu] Love vs friendship
If a = 1, b = 2, c = 3 ... z = 26
Then l + o + v + e = 54
and f + r + i + e + n + d + s + h + i + p = 108
So friendship is twice as strong as love :-)
Your task is to write a function which calculates the value of a word based off the sum of the alphabet positions of its characters.
The input will always be made of only lowercase letters and will never be empty.
翻译:
如果a=1,b=2,c=3…z=26
那么l+o+v+e=54
并且f+r+i+e+n+d+s+h+i+p=108
所以友谊是爱情的两倍:
你的任务是编写一个函数,它根据一个单词的字母位置的总和来计算单词的值。
输入将始终由小写字母组成,并且永远不会为空。
解:
function wordsToMarks(string){
return string.split("").map(x=>x.charCodeAt()-96).reduce((a,b)=>a+b)
}
[8 kyu] Pillars
There are pillars near the road. The distance between the pillars is the same and the width of the pillars is the same. Your function accepts three arguments:
number of pillars (≥ 1);
distance between pillars (10 - 30 meters);
width of the pillar (10 - 50 centimeters).
Calculate the distance between the first and the last pillar in centimeters (without the width of the first and last pillar).
翻译:
道路附近有柱子。柱子之间的距离相同,柱子的宽度相同。您的函数接受三个参数:
支柱数量(≥ 1);
支柱之间的距离(10-30米);
柱子的宽度(10-50厘米)。
计算第一根柱子和最后一根柱子之间的距离,单位为厘米(不包括第一根和最后一个柱子的宽度)。
解:
function pillars(numPill, dist, width) {
return numPill > 2 ? (numPill-2)*width + (numPill-1)*dist*100 : 100* dist*(numPill-1)
}
[7 kyu] No oddities here
Write a small function that returns the values of an array that are not odd.
All values in the array will be integers. Return the good values in the order they are given.
翻译:
编写一个返回非奇数数组值的小函数。
数组中的所有值都是整数。按给出的顺序返回正确的值。
解:
function noOdds( values ){
return values.filter(x=>x%2==0)
}
[8 kyu] Regexp Basics - is it a digit?
Implement String#digit? (in Java StringUtils.isDigit(String)), which should return true if given object is a digit (0-9), false otherwise.
翻译:
实现字符串#数字?(在Java StringUtils.isDigit(String)中),如果给定对象是数字(0-9),则返回true,否则返回false。
解:
String.prototype.digit = function() {
return /^\d$/.test(this);
};