Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

(Note: Remarks in my first review first review about handling special cases and the returning a value still apply.)

(Note: Remarks in my first review about handling special cases and the returning a value still apply.)

(Note: Remarks in my first review about handling special cases and the returning a value still apply.)

deleted 1 characters in body
Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 478
function transposeString(str) {
 if (str == null) return str;
 var words = str.split(' ');
 var maxWordLength = _.max(_.pluck(words, 'length'));
 return _.range(maxWordLength).map(
 // Generate a line of output using the nth character forof each word
 function outputLineUsingNthChar(n) {
 return words.map(
 // Extract the nth character of a word, space-padded if needed
 function nthCharWithSpacePadding(word) {
 return n < word.length ? word.charAt(n) : ' ';
 }
 ).join('');
 }
 ).join("\n");
}
function transposeString(str) {
 if (str == null) return str;
 var words = str.split(' ');
 var maxWordLength = _.max(_.pluck(words, 'length'));
 return _.range(maxWordLength).map(
 // Generate a line of output using the nth character for each word
 function outputLineUsingNthChar(n) {
 return words.map(
 // Extract the nth character of a word, space-padded if needed
 function nthCharWithSpacePadding(word) {
 return n < word.length ? word.charAt(n) : ' ';
 }
 ).join('');
 }
 ).join("\n");
}
function transposeString(str) {
 if (str == null) return str;
 var words = str.split(' ');
 var maxWordLength = _.max(_.pluck(words, 'length'));
 return _.range(maxWordLength).map(
 // Generate a line of output using the nth character of each word
 function outputLineUsingNthChar(n) {
 return words.map(
 // Extract the nth character of a word, space-padded if needed
 function nthCharWithSpacePadding(word) {
 return n < word.length ? word.charAt(n) : ' ';
 }
 ).join('');
 }
 ).join("\n");
}
deleted 31 characters in body
Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 478

I would like to point out that yourYour solution feels a little like functional programming, though not quite. What if you go all the way with functional programming? Your solution was already quite close; you just need to replace .forEach() with .map(). Here's how it could look:

I would like to point out that your solution feels a little like functional programming, though not quite. What if you go all the way with functional programming? Your solution was already quite close; you just need to replace .forEach() with .map(). Here's how it could look:

Your solution feels a little like functional programming, though not quite. What if you go all the way with functional programming? Your solution was already quite close; you just need to replace .forEach() with .map(). Here's how it could look:

Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 478
Loading
default

AltStyle によって変換されたページ (->オリジナル) /