1.
It's pretty straightforward. Your goal is to create a function that removes the first and last characters of a string. You're given one parameter, except in C, where, to keep the difficulty at the level of the kata, you are given two parameters, the first a buffer with length exactly the same as the second parameter, the original string. You don't have to worry with strings with less than two characters.
代码:
function removeChar(str) { return str.slice(1, -1); }
2
#Find the missing letter Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array. You will always get an valid array. And it will be always exactly one letter be missing. The length of the array will always be at least 2. The array will always contain letters in only one case. Example: ['a','b','c','d','f'] -> 'e' ['O','Q','R','S'] -> 'P' (Use the English alphabet with 26 letters!) Have fun coding it and please don't forget to vote and rank this kata! :-) I have also created other katas. Take a look if you enjoyed this kata!
代码:
function findMissingLetter(array) { var str = array.join(""); for (var i = 0, l = str.length,r=""; i < l; i++) { if (str.charCodeAt(i+1) - str.charCodeAt(i)!= 1) { return String.fromCharCode(str.charCodeAt(i)+1) } } }