
Codewars
Codewars记录与题解分享
cbat01
这个作者很懒,什么都没留下…
展开
-
【Codewars】<8kyu>Sum Mixed Array
题目Given an array of integers as strings and numbers, return the sum of the array values as if all were numbers.Return your answer as a number.这道题目要我们实现的是,计算数组所有项的和,数组包含数字跟字符串,如果是字符串的话,转成数字计算。结果返回数字类型。即使用js计算数组各项总和,数组可能包括字符串例子sumMix([9, 3, '7', '3'原创 2021-01-06 16:14:49 · 392 阅读 · 0 评论 -
【Codewars】<4kyu>Sum Strings as Numbers
题目<4kyu>Sum Strings as NumbersGiven the string representations of two integers, return the string representation of the sum of those integers.A string representation of an integer will contain no characters besides the ten numerals “0” to “9”.给定两个整数.原创 2020-12-30 17:19:43 · 899 阅读 · 0 评论 -
【Codewars】<7kyu>By 3, or not by 3? That is the question . . .
题目A trick I learned in elementary school to determine whether or not a number was divisible by three is to add all of the integers in the number together and to divide the resulting sum by three. If there is no remainder from dividing the sum by three, t原创 2020-12-29 10:09:34 · 195 阅读 · 0 评论 -
【Codewars】<7kyu> Return a string‘s even characters.
题目Write a function that returns a sequence (index begins with 1) of all the even characters from a string. If the string is smaller than two characters or longer than 100 characters, the function should return “invalid string”.编写一个函数,返回字符串中所有偶数位置的字符(索引原创 2020-12-28 18:15:51 · 368 阅读 · 0 评论 -
【Codewars】<6kyu>Detect Pangram
一、题目A pangram is a sentence that contains every single letter of the alphabet at least once. For example, the sentence “The quick brown fox jumps over the lazy dog” is a pangram, because it uses the letters A-Z at least once (case is irrelevant).Given a原创 2020-12-28 14:27:27 · 595 阅读 · 0 评论 -
【Codewars】<7kyu>Char Code Calculation
题目:Given a string, turn each character into its ASCII character code and join them together to create a number - let's call this number total1:'ABC' --> 'A' = 65, 'B' = 66, 'C' = 67 --> 656667Then replace any incidence of the number 7 with the nu原创 2020-12-27 16:06:16 · 619 阅读 · 1 评论 -
【Codewars】<7kyu> Unique string characters
题目:In this Kata, you will be given two strings a and b and your task will be to return the characters that are not common in the two strings.这道题目中,接收两个字符串a和b,目的是返回这两个字符串中不重复的字符。例子solve("xyab","xzca") // "ybzc" solve("xyab","xzca") // "ybzc"solve(原创 2020-12-24 18:13:26 · 397 阅读 · 1 评论 -
【Codewars】<6kyu>Calculate String Rotation
一、题目:Write a function that receives two strings and returns n, where n is equal to the number of characters we should shift the first string > forward to match the second.For instance, take the strings “fatigue” and “tiguefa”. In this case, the fir原创 2020-12-23 18:22:18 · 310 阅读 · 0 评论 -
【Codewars】<6kyu>What century is it?
题目:Return the century of the input year. The input will always be a 4 digit string, so there is no need for validation.返回输入年份的世纪。输入总是一个4位数的字符串,因此不需要验证。示例:"1999" --> "20th""2011" --> "21st""2154" --> "22nd""2259" --> "23rd""1124" --&g原创 2020-12-23 11:37:48 · 260 阅读 · 0 评论 -
【Codewars】<7kyu> Vowel Count
一、题目:Return the number (count) of vowels in the given string.这道题要实现的是返回字符串中的元音个数(a,e,i,o,u)二、例子:getCount("abracadabra"), 5三、题解一:// 题解一:function getCount(str) { var vowelsCount = 0; // enter your majic here var arr = str.split('');原创 2020-12-22 17:38:30 · 229 阅读 · 0 评论 -
【Codewars】<3kyu>Calculator
题目:Create a simple calculator that given a string of operators (), +, -, *, / and numbers separated by spaces returns the value of that expression这个题目要我们实现一个简单的计算器,计算出带加减乘除的字符串运算后的值。例子:Calculator().evaluate("2 / 2 + 3 * 4 - 6") # => 7题解一:// 方法一原创 2020-12-22 14:07:02 · 418 阅读 · 0 评论 -
【Codewars】<5kyu> ISBN-10 Validation
一、题目:ISBN-10 identifiers are ten digits long. The first nine characters are digits 0-9. The last digit can be 0-9 or X, to indicate a value of 10.An ISBN-10 number is valid if the sum of the digits multiplied by their position modulo 11 equals zero.这道原创 2020-12-21 17:35:07 · 233 阅读 · 0 评论 -
【Codewars】<5kyu> Moving Zeros To The End
题目:Write an algorithm that takes an array and moves all of the zeros tothe end, preserving the order of the other elements.这道题目要我们实现的是,将一个数组中所有的零移到最后,其他元素保持顺序不变。moveZeros([false,1,0,1,2,0,1,3,"a"]) // returns[false,1,1,2,1,3,"a",0,0]测试用例:moveZero原创 2020-12-21 15:59:45 · 236 阅读 · 0 评论