6 kyu

Midpoint inception

Description:

Write

function midPoint(str)

that takes all the words in a string str and cumulatively appends their midpoints

For example:

midPoint('abc') === 'b'
midPoint('abcd') === 'bc' // when length is even, then midpoint is 2 chars
midPoint('abcdefg') === 'dbf' 
// 'd' is the midpoint of 'abcdefg' (abc)d(efg) --> go left split first
// 'b' is the midpoint 'abc'
// 'f' is the midpoint of 'efg'
midPoint('abcdefgh') === 'debg'
// 'de' is midpoint of 'abcdefgh' (abc)de(fgh)
// 'b' is midpoint of 'abc'
// 'g' is midpoint of 'fgh'
midPoint('abcdefghij1234567890') === 'j1ebcgh63489'
// 'j1' is midpoint of 'abcdefghij1234567890' (abcdefghi)j1(234567890)
// 'e' is midpoint of 'abcdefghi' (abcd)e(fghi)
// 'bc' is midpoint of 'abcd' (a)bc(d)
// 'gh' is midpoint of 'fghi' (f)gh(i)
// '6' is midpoint of '234567890' (2345)6(7890)
// '34' is midpoint of '2345' (2)34(5)
// '89' is midpoint of '7890' (7)89(0)

midPoint('abc def') === 'b e' // words can be space seperated
midPoint('a ab abc abcd abcde abcdef abcdefg abcdefgh abcdefghi abcdefghij') === '  b bc c cd dbf debg ebcgh efbchi'

Notes:

  • Always go left and then right when finding midpoints
  • Keep all the whitespaces of the original sentence
  • A "word", here is a sequence of chars delimited by whitespaces or beginning or end of string.
Algorithms

Similar Kata:

Stats:

CreatedMar 2, 2016
PublishedMar 2, 2016
Warriors Trained233
Total Skips8
Total Code Submissions290
Total Times Completed87
JavaScript Completions87
Total Stars8
% of votes with a positive feedback rating93% of 37
Total "Very Satisfied" Votes33
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes1
Total Rank Assessments8
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • joh_pot Avatar
  • smile67 Avatar
  • Blind4Basics Avatar
Ad