No Loops 3 - Copy Within - Shortest Code Version
Description:
Maximum solution length = *** 51 characters***
For this kata you need to return the provided array, with the same length as provided, but with some of the values copied, and that copied section duplicated over another section. An example should help:
You will be given an array, a start and stop index for the 'copy', and an index to insert it to.
For example function copy(array, start, stop, place){}
where:
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; start = 5; stop = 8; place = 2;
In this example, the copy bit begins at (and includes) index 5. So, the first value copied is 6. The copy stops at (and does not include) index 8, and so includes all values up to and including 8 (index 8 is '9' and is not included).
This means the copied element is [6, 7, 8];
You now have to put this copied element into the array at the index specified by 'place'. Note the copied bit also remains at it's original location, hence 'copy', not 'move'. When inserted, the copied elements overwrite others in the array so that the length does not increase.
so in this example [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; becomes: [1, 2, 6, 7, 8, 6, 7, 8, 9, 10];
[1, 2, (6, 7, 8), 6, 7, 8, 9, 10]; <- brackets for highlighting insertion only
Makes sense? Give it a go... hint... there is an array method that is very helpful for this job. So for that reason, you aren't allowed to use loops... :D
Similar Kata:
Stats:
Created | Sep 4, 2016 |
Warriors Trained | 110 |
Total Skips | 18 |
Total Code Submissions | 218 |
Total Times Completed | 56 |
JavaScript Completions | 56 |
Total Stars | 2 |
% of votes with a positive feedback rating | 70% of 38 |
Total "Very Satisfied" Votes | 22 |
Total "Somewhat Satisfied" Votes | 9 |
Total "Not Satisfied" Votes | 7 |
Total Rank Assessments | 36 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 8 kyu |