Write a function to convert a name into initials. This kata strictly takes two words with one space in between them.
The output should be two capital letters with a dot separating them.
It should look like this:
Sam Harris
=> S.H
patrick feeney
=> P.F
function abbrevName(name){
return name.split(" ").map(item =>item[0].toUpperCase()).join('.')
}
function abbrevName(name){
var nameArray = name.split(" ");
return (nameArray[0][0] + "." + nameArray[1][0]).toUpperCase();
}
function abbrevName(name){
return name.split(' ').map(x => x.substr(0, 1).toUpperCase()).join('.');
}
const abbrevName = name => name.match(/\b\w/g).join('.').toUpperCase()
function abbrevName(name){
return name[0].toUpperCase() + "." + name[name.indexOf(" ")+1].toUpperCase();
}
Write a function to split a string and convert it into an array of words.
"Robin Singh" ==> ["Robin", "Singh"]
"I love arrays they are my favorite" ==> ["I", "love", "arrays", "they", "are", "my", "favorite"]
function stringToArray(string){
return string.split(" ");
}
Given an array of integers your solution should find the smallest integer.
For example:
[34, 15, 88, 2]
your solution will return 2
[34, -345, -1, 100]
your solution will return 345
You can assume, for the purpose of this kata, that the supplied array will not be empty.
class SmallestIntegerFinder {
findSmallestInt(args) {
return Math.min(...args)
}
}
class SmallestIntegerFinder {
findSmallestInt(args) {
return Math.min.apply(null, args);
}
}
class SmallestIntegerFinder {
findSmallestInt(args) {
return args.sort((a,b)=>a-b)[0];
}
}
class SmallestIntegerFinder {
findSmallestInt(args) {
return args.reduce(function(prev, curr, index, array) {
return prev < curr ? prev : curr;
});
}
}