codewars 闯关纪录
- 1. 2019/6/24
- 2. Find The Parity Outlier
- 3. Format a string of names like ‘Bart, Lisa & Maggie’
- 4. Jaden Casing Strings
- 5. 2019/6/25
- 6. Sum of the first nth term of Series
- 7. Exes and Ohs(统计相同数量的o和x)
- 8. Equal Sides Of An Array
- 9. Does my number look big in this?
- 10. 2019/6/26
- 11. IQ Test
- 12. 2019/6/27
- 13. Find the missing letter
- 14. Roman Numerals Encoder
- 15. 2019/6/28
- 16. Persistent Bugger
- 17. Is a number prime
- 18. Where my anagrams at?
- 19. 2019/7/9
- 20. Permutations
- 21. 2019/7/14
- 22. First non-repeating character
2019/6/24
[2, 4, 0, 100, 4, 11, 2602, 36]
Should return: 11 (the only odd number)[160, 3, 1719, 19, 11, 13, -21]
Should return: 160 (the only even number)
1 | // mine |
1 | // the best |
list([ {name: ‘Bart’}, {name: ‘Lisa’}, {name: ‘Maggie’} ])
// returns ‘Bart, Lisa & Maggie’list([ {name: ‘Bart’}, {name: ‘Lisa’} ])
// returns ‘Bart & Lisa’list([ {name: ‘Bart’} ])
// returns ‘Bart’list([])
// returns ‘’
1 | // mine |
1 | // the best |
Not Jaden-Cased: “How can mirrors be real if our eyes aren’t real”
Jaden-Cased: “How Can Mirrors Be Real If Our Eyes Aren’t Real”
1 | // mine |
1 | // the best |
2019/6/25
SeriesSum(1) => 1 = “1.00”
SeriesSum(2) => 1 + 1/4 = “1.25”
SeriesSum(5) => 1 + 1/4 + 1/7 + 1/10 + 1/13 = “1.57”
1 | // mine |
1 | // the best |
1 | // mine |
1 | // the best |
找到一个索引N,其中N左边的整数和等于右边的整数和,如果没有请返回
-1
1
2
3
4 Test.assertEquals(findEvenIndex([1,2,3,4,3,2,1]),3, "The array was: [1,2,3,4,3,2,1] \n");
Test.assertEquals(findEvenIndex([1,100,50,-51,1,1]),1, "The array was: [1,100,50,-51,1,1] \n");
Test.assertEquals(findEvenIndex([1,2,3,4,5,6]),-1, "The array was: [1,2,3,4,5,6] \n");
Test.assertEquals(findEvenIndex([20,10,30,10,10,15,35]),3, "The array was: [20,10,30,10,10,15,35] \n");
1 | // mine |
1 | // the best |
自恋数是一个数字,它是自己数字的总和,每个数字都增加到给定基数中的数字位数。
1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
1^4 + 6^4 + 3^4 + 4^4 = 1 + 1296 + 81 + 256 = 1634
1 | // mine |
1 | // the best |
2019/6/26
iqTest(“2 4 7 8 10”) => 3 // Third number is odd, while the rest of the numbers are even
iqTest(“1 2 1 1”) => 2 // Second number is even, while the rest of the numbers are odd
1 | // mine |
1 | // the best |
2019/6/27
[‘a’,’b’,’c’,’d’,’f’] -> ‘e’
[‘O’,’Q’,’R’,’S’] -> ‘P’
(Use the English alphabet with 26 letters!)
1 | // mine |
1 | // the best |
solution(1000); // should return ‘M’
把数字转化为罗马数字
1
2
3
4
5
6
7
8
9
10 // help
Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1,000
```// the best
function solution(number){
// convert the number to a roman numeral
var roman = {M:1000,CM:900, D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1 }
var ans = ‘’;
while(number>0){
for(a in roman){
if(roman[a]<=number){ ans += a; number-=roman[a]; break;}
}
}
return ans;
}
1 | - # Stop gninnipS My sdroW! |
// mine
function spinWords(str){
return str.split(‘ ‘).map(v => v.length>=5 ? v.split(‘’).reverse().join(‘’) : v ).join(‘ ‘)
}
1 | ``` |
2019/6/28
1
2
3
4
5
6
7 persistence(39) === 3 // because 3*9 = 27, 2*7 = 14, 1*4=4
// and 4 has only one digit
persistence(999) === 4 // because 9*9*9 = 729, 7*2*9 = 126,
// 1*2*6 = 12, and finally 1*2 = 2
persistence(4) === 0 // because 4 is already a one-digit number
1 | // mine |
1 | // the best |
is_prime(1) /* false /
is_prime(2) / true /
is_prime(-1) / false */
是否为质数
1 | // mine |
1 | // the best |
1
2
3
4
5
6
7
8
9
10
11
12
13 'abba' & 'baab' == true
'abba' & 'bbaa' == true
'abba' & 'abbba' == false
'abba' & 'abca' == false
>anagrams('abba', ['aabb', 'abcd', 'bbaa', 'dada']) => ['aabb', 'bbaa']
>anagrams('racer', ['crazer', 'carer', 'racar', 'caers', 'racer']) => ['carer', 'racer']
>anagrams('laser', ['lazing', 'lazy', 'lacer']) => []
1 | // mine |
1 | // the best |
2019/7/9
您必须创建输入字符串的所有排列并删除重复项(如果存在)。
1
2
3 permutations('a'); // ['a']
permutations('ab'); // ['ab', 'ba']
permutations('aabb'); // ['aabb', 'abab', 'abba', 'baab', 'baba', 'bbaa']
1 | // mine |
1 | // the best |
2019/7/14
‘a’ => ‘a’
‘stress’ => ‘t’
‘Moonmen’ => ‘e’
1 | // mine |
1 | // the best |