formatting
language_fundamentals
strings
Given two strings,
firstName
andlastName
, return a single string in the format “last, first”.
concatName("First", "Last") // "Last, First"
concatName("John", "Doe") // "Doe, John"
concatName("Mary", "Jane") // "Jane, Mary"
return
the result.function concatName(firstName, lastName) {
return lastName.concat(", ").concat(firstName);
}
let Test = (function(){
return {
assertEquals:function(actual,expected){
if(actual !== expected){
let errorMsg = `actual is ${actual},${expected} is expected`;
throw new Error(errorMsg);
}
},
assertSimilar:function(actual,expected){
if(actual.length != expected.length){
throw new Error(`length is not equals, ${actual},${expected}`);
}
for(let a of actual){
if(!expected.includes(a)){
throw new Error(`missing ${a}`);
}
}
}
}
})();
Test.assertEquals(concatName("John", "Doe"), "Doe, John")
Test.assertEquals(concatName("First", "Last"), "Last, First")
Test.assertEquals(concatName("A", "B"), "B, A")
// In case someone is making odd assumptions about comma characters.
Test.assertEquals(concatName(",", ","), ",, ,")