Created
January 8, 2018 10:54
-
-
Save AndrewBestbier/7614759f18fa55a3370d9cb6cee13d36 to your computer and use it in GitHub Desktop.
My solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const values = [1, 2, 3, 'a', 'b', 'c']; | |
// [] -> [] | |
// [x] -> [x] | |
// x: xs : y -> [x, y] ++ func(xs) | |
const melder = values => { | |
if (values.length <= 1) { | |
return values; | |
} | |
const head = values[0]; | |
const tail = values[values.length - 1]; | |
const body = values.slice(1, values.length - 1); | |
return [head, tail].concat(melder(body)); | |
}; | |
const res = melder(values); | |
console.log('res', res); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment