Last active
July 5, 2016 21:14
-
-
Save mohayonao/a1981566ec4cd433fd22fa5e40a7ea52 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| module.exports = { | |
| "Up": [ 0, 1, 2, 3 ], | |
| "Down": [ 3, 2, 1, 0 ], | |
| "UpDown": [ 0, 1, 2, 3, 2, 1 ], | |
| "DownUp": [ 3, 2, 1, 0, 1, 2 ], | |
| "Down&Up": [ 3, 2, 1, 0, 0, 1, 2, 3 ], | |
| "Up&Down": [ 0, 1, 2, 3, 3, 2, 1, 0 ], | |
| "Converge": [ 0, 3, 1, 2 ], | |
| "Diverge": [ 2, 1, 3, 0 ], | |
| "Con&Diverge": [ 0, 3, 1, 2, 1, 3 ], | |
| "PinkyUp": [ 0, 3, 1, 3, 2, 3 ], | |
| "PinkyUpDown": [ 0, 3, 1, 3, 2, 3, 1, 3 ], | |
| "ThumbUp": [ 0, 1, 0, 2, 0, 3 ], | |
| "ThumbUpDown": [ 0, 1, 0, 2, 0, 3, 0, 2 ] | |
| }; |
This file contains hidden or 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
| "use strict"; | |
| function up(list) { | |
| return toArray(list).sort(asc); | |
| } | |
| function down(list) { | |
| return toArray(list).sort(desc); | |
| } | |
| function upDown(list) { | |
| list = toArray(list).sort(asc); | |
| return list.concat(list.slice(1, -1).reverse()); | |
| } | |
| function downUp(list) { | |
| list = toArray(list).sort(desc); | |
| return list.concat(list.slice(1, -1).reverse()); | |
| } | |
| function upAndDown(list) { | |
| list = toArray(list).sort(asc); | |
| return list.concat(list.slice().reverse()); | |
| } | |
| function downAndUp(list) { | |
| list = toArray(list).sort(desc); | |
| return list.concat(list.slice().reverse()); | |
| } | |
| function converge(list) { | |
| var result = []; | |
| list = toArray(list).sort(asc); | |
| while (list.length) { | |
| result.push(list.shift()); | |
| if (list.length) { | |
| result.push(list.pop()); | |
| } | |
| } | |
| return result; | |
| } | |
| function diverge(list) { | |
| return converge(list).reverse(); | |
| } | |
| function conAndDiverge(list) { | |
| list = converge(list); | |
| return list.concat(list.slice(1, -1).reverse()); | |
| } | |
| function pinkyUp(list) { | |
| list = toArray(list).sort(asc); | |
| var x = list.pop(); | |
| return list.reduce((a, b) => a.concat(b, x), []); | |
| } | |
| function pinkyUpDown(list) { | |
| list = toArray(list).sort(asc); | |
| var x = list.pop(); | |
| list = list.concat(list.slice(1, -1).reverse()); | |
| return list.reduce((a, b) => a.concat(b, x), []); | |
| } | |
| function thumbUp(list) { | |
| list = toArray(list).sort(asc); | |
| var x = list.shift(); | |
| return list.reduce((a, b) => a.concat(x, b), []); | |
| } | |
| function thumbUpDown(list) { | |
| list = toArray(list).sort(asc); | |
| var x = list.shift(); | |
| list = list.concat(list.slice(1, -1).reverse()); | |
| return list.reduce((a, b) => a.concat(x, b), []); | |
| } | |
| function toArray(list) { | |
| return Array.prototype.slice.call(list); | |
| } | |
| function asc(a, b) { | |
| return a - b; | |
| } | |
| function desc(a, b) { | |
| return b - a; | |
| } | |
| module.exports = { | |
| "Up": up, | |
| "Down": down, | |
| "UpDown": upDown, | |
| "DownUp": downUp, | |
| "Up & Down": upAndDown, | |
| "Down & Up": downAndUp, | |
| "Converge": converge, | |
| "Diverge": diverge, | |
| "Con & Diverge": conAndDiverge, | |
| "Pinky Up": pinkyUp, | |
| "Pinky UpDown": pinkyUpDown, | |
| "Thumb Up": thumbUp, | |
| "Thumb UpDown": thumbUpDown | |
| }; | |
| var arp = module.exports; | |
| var chord = [ 0, 2, 1, 3, 4, 5 ]; | |
| for (let name in arp) { | |
| console.log(name, arp[name](chord)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment