Instantly share code, notes, and snippets.

Embed
What would you like to do?
javascript console snippet, simple recursion and map-fun with arrays
const sl = (array, extra) => {
extra = extra || 1;
console.log('-'.repeat(extra),array[0].title, array[1].title, array[2].title, array[3].title, array[4].title, array[5].title, array[6].title);
return array.length === 7 ? "simple slicing done" : sl(array.slice(1), extra=extra+1);
};
const shuffleArray = arr => (
arr
.map(a => [Math.random(), a])
.sort((a, b) => a[0] - b[0])
.map(a => a[1])
);
const sh = (array, extra) => {
extra = extra || 1;
console.log('-'.repeat(extra),array[0].title, array[1].title, array[2].title, array[3].title, array[4].title, array[5].title, array[6].title);
return array.length === 7 ? "shuffled slicer done" : sh(shuffleArray(array).slice(1), extra=extra+1);
};
arr = $.map($.find('.tile'), (ele) => { var it = $(ele).find('svg'); return { 'val': parseInt($(it).attr('title'), 16), 'obj': ele, 'title': $(it).attr('title') }; }).sort((first,second) => first.val - second.val);
sl(arr);
sh(arr);
VM952:3 - 05b757adb1f685b9c90f140aefcc150e 06e54258fdcc0164a6ed8fddeacda1b9 0e382d212fbebf86f057f4b42fe82756 1edfb00014fe36772d5b26154d75baeb 242e81c890c87f27caae68054b1541ba 2b177576d4350dba60937384231f042e 39840efcdfd5a485c4031a72074dd247
VM952:3 -- 06e54258fdcc0164a6ed8fddeacda1b9 0e382d212fbebf86f057f4b42fe82756 1edfb00014fe36772d5b26154d75baeb 242e81c890c87f27caae68054b1541ba 2b177576d4350dba60937384231f042e 39840efcdfd5a485c4031a72074dd247 4a4f846bc9fd593e8b3d94a54cc46c28
VM952:3 --- 0e382d212fbebf86f057f4b42fe82756 1edfb00014fe36772d5b26154d75baeb 242e81c890c87f27caae68054b1541ba 2b177576d4350dba60937384231f042e 39840efcdfd5a485c4031a72074dd247 4a4f846bc9fd593e8b3d94a54cc46c28 56434bd529129e86f20ec6079585a6c0
VM952:3 ---- 1edfb00014fe36772d5b26154d75baeb 242e81c890c87f27caae68054b1541ba 2b177576d4350dba60937384231f042e 39840efcdfd5a485c4031a72074dd247 4a4f846bc9fd593e8b3d94a54cc46c28 56434bd529129e86f20ec6079585a6c0 6b1373be53f55472142514832dd0469f
VM952:3 ----- 242e81c890c87f27caae68054b1541ba 2b177576d4350dba60937384231f042e 39840efcdfd5a485c4031a72074dd247 4a4f846bc9fd593e8b3d94a54cc46c28 56434bd529129e86f20ec6079585a6c0 6b1373be53f55472142514832dd0469f 856bf544fd593866b0b0c3a19f8c4f11
VM952:3 ------ 2b177576d4350dba60937384231f042e 39840efcdfd5a485c4031a72074dd247 4a4f846bc9fd593e8b3d94a54cc46c28 56434bd529129e86f20ec6079585a6c0 6b1373be53f55472142514832dd0469f 856bf544fd593866b0b0c3a19f8c4f11 87ec6fc98b526d1d2abe64ad3b7fe14f
VM952:3 ------- 39840efcdfd5a485c4031a72074dd247 4a4f846bc9fd593e8b3d94a54cc46c28 56434bd529129e86f20ec6079585a6c0 6b1373be53f55472142514832dd0469f 856bf544fd593866b0b0c3a19f8c4f11 87ec6fc98b526d1d2abe64ad3b7fe14f 889c7bd62dd16088c5c3e31c4fb41080
VM952:3 -------- 4a4f846bc9fd593e8b3d94a54cc46c28 56434bd529129e86f20ec6079585a6c0 6b1373be53f55472142514832dd0469f 856bf544fd593866b0b0c3a19f8c4f11 87ec6fc98b526d1d2abe64ad3b7fe14f 889c7bd62dd16088c5c3e31c4fb41080 92bc1cd050877f7a4e7e6741e4d3d992
VM952:3 --------- 56434bd529129e86f20ec6079585a6c0 6b1373be53f55472142514832dd0469f 856bf544fd593866b0b0c3a19f8c4f11 87ec6fc98b526d1d2abe64ad3b7fe14f 889c7bd62dd16088c5c3e31c4fb41080 92bc1cd050877f7a4e7e6741e4d3d992 b39a1560417a6b0a96d64112b3743312
VM952:3 ---------- 6b1373be53f55472142514832dd0469f 856bf544fd593866b0b0c3a19f8c4f11 87ec6fc98b526d1d2abe64ad3b7fe14f 889c7bd62dd16088c5c3e31c4fb41080 92bc1cd050877f7a4e7e6741e4d3d992 b39a1560417a6b0a96d64112b3743312 be018fc31e579e56388f429bf05b6ff8
VM952:3 ----------- 856bf544fd593866b0b0c3a19f8c4f11 87ec6fc98b526d1d2abe64ad3b7fe14f 889c7bd62dd16088c5c3e31c4fb41080 92bc1cd050877f7a4e7e6741e4d3d992 b39a1560417a6b0a96d64112b3743312 be018fc31e579e56388f429bf05b6ff8 bf63f176c652c41d0df0b599f3c152de
VM952:3 ------------ 87ec6fc98b526d1d2abe64ad3b7fe14f 889c7bd62dd16088c5c3e31c4fb41080 92bc1cd050877f7a4e7e6741e4d3d992 b39a1560417a6b0a96d64112b3743312 be018fc31e579e56388f429bf05b6ff8 bf63f176c652c41d0df0b599f3c152de d1026a12cae04cc9193f2ff44a3aa920
VM952:3 ------------- 889c7bd62dd16088c5c3e31c4fb41080 92bc1cd050877f7a4e7e6741e4d3d992 b39a1560417a6b0a96d64112b3743312 be018fc31e579e56388f429bf05b6ff8 bf63f176c652c41d0df0b599f3c152de d1026a12cae04cc9193f2ff44a3aa920 d7dd42cfea06f9ed6237a54812304739
VM952:3 -------------- 92bc1cd050877f7a4e7e6741e4d3d992 b39a1560417a6b0a96d64112b3743312 be018fc31e579e56388f429bf05b6ff8 bf63f176c652c41d0df0b599f3c152de d1026a12cae04cc9193f2ff44a3aa920 d7dd42cfea06f9ed6237a54812304739 e985c769a468d0f3f09cb71ab5481fe6
VM952:3 --------------- b39a1560417a6b0a96d64112b3743312 be018fc31e579e56388f429bf05b6ff8 bf63f176c652c41d0df0b599f3c152de d1026a12cae04cc9193f2ff44a3aa920 d7dd42cfea06f9ed6237a54812304739 e985c769a468d0f3f09cb71ab5481fe6 e9d664c5bae5fbd8c6885586cc6eb2ca
VM952:3 ---------------- be018fc31e579e56388f429bf05b6ff8 bf63f176c652c41d0df0b599f3c152de d1026a12cae04cc9193f2ff44a3aa920 d7dd42cfea06f9ed6237a54812304739 e985c769a468d0f3f09cb71ab5481fe6 e9d664c5bae5fbd8c6885586cc6eb2ca fa191c6b30f3c65bd22ddfd5a0fd111e
VM952:3 ----------------- bf63f176c652c41d0df0b599f3c152de d1026a12cae04cc9193f2ff44a3aa920 d7dd42cfea06f9ed6237a54812304739 e985c769a468d0f3f09cb71ab5481fe6 e9d664c5bae5fbd8c6885586cc6eb2ca fa191c6b30f3c65bd22ddfd5a0fd111e fb45e3160a99b78706c76ac20909ccd0
VM952:3 ------------------ d1026a12cae04cc9193f2ff44a3aa920 d7dd42cfea06f9ed6237a54812304739 e985c769a468d0f3f09cb71ab5481fe6 e9d664c5bae5fbd8c6885586cc6eb2ca fa191c6b30f3c65bd22ddfd5a0fd111e fb45e3160a99b78706c76ac20909ccd0 fd64b6e8d5f6bce831d59c206d23b535
VM952:3 ------------------- d7dd42cfea06f9ed6237a54812304739 e985c769a468d0f3f09cb71ab5481fe6 e9d664c5bae5fbd8c6885586cc6eb2ca fa191c6b30f3c65bd22ddfd5a0fd111e fb45e3160a99b78706c76ac20909ccd0 fd64b6e8d5f6bce831d59c206d23b535 fe518192402e9566076a27ca6539ac44
VM952:14 - 05b757adb1f685b9c90f140aefcc150e 06e54258fdcc0164a6ed8fddeacda1b9 0e382d212fbebf86f057f4b42fe82756 1edfb00014fe36772d5b26154d75baeb 242e81c890c87f27caae68054b1541ba 2b177576d4350dba60937384231f042e 39840efcdfd5a485c4031a72074dd247
VM952:14 -- 0e382d212fbebf86f057f4b42fe82756 e985c769a468d0f3f09cb71ab5481fe6 56434bd529129e86f20ec6079585a6c0 39840efcdfd5a485c4031a72074dd247 87ec6fc98b526d1d2abe64ad3b7fe14f 05b757adb1f685b9c90f140aefcc150e d7dd42cfea06f9ed6237a54812304739
VM952:14 --- e9d664c5bae5fbd8c6885586cc6eb2ca d1026a12cae04cc9193f2ff44a3aa920 856bf544fd593866b0b0c3a19f8c4f11 889c7bd62dd16088c5c3e31c4fb41080 87ec6fc98b526d1d2abe64ad3b7fe14f bf63f176c652c41d0df0b599f3c152de 2b177576d4350dba60937384231f042e
VM952:14 ---- 1edfb00014fe36772d5b26154d75baeb d7dd42cfea06f9ed6237a54812304739 b39a1560417a6b0a96d64112b3743312 d1026a12cae04cc9193f2ff44a3aa920 856bf544fd593866b0b0c3a19f8c4f11 4a4f846bc9fd593e8b3d94a54cc46c28 39840efcdfd5a485c4031a72074dd247
VM952:14 ----- 05b757adb1f685b9c90f140aefcc150e be018fc31e579e56388f429bf05b6ff8 b39a1560417a6b0a96d64112b3743312 d1026a12cae04cc9193f2ff44a3aa920 889c7bd62dd16088c5c3e31c4fb41080 56434bd529129e86f20ec6079585a6c0 39840efcdfd5a485c4031a72074dd247
VM952:14 ------ 1edfb00014fe36772d5b26154d75baeb 2b177576d4350dba60937384231f042e 05b757adb1f685b9c90f140aefcc150e bf63f176c652c41d0df0b599f3c152de d1026a12cae04cc9193f2ff44a3aa920 889c7bd62dd16088c5c3e31c4fb41080 4a4f846bc9fd593e8b3d94a54cc46c28
VM952:14 ------- e985c769a468d0f3f09cb71ab5481fe6 4a4f846bc9fd593e8b3d94a54cc46c28 fa191c6b30f3c65bd22ddfd5a0fd111e 856bf544fd593866b0b0c3a19f8c4f11 05b757adb1f685b9c90f140aefcc150e 56434bd529129e86f20ec6079585a6c0 2b177576d4350dba60937384231f042e
VM952:14 -------- be018fc31e579e56388f429bf05b6ff8 fd64b6e8d5f6bce831d59c206d23b535 2b177576d4350dba60937384231f042e e985c769a468d0f3f09cb71ab5481fe6 856bf544fd593866b0b0c3a19f8c4f11 06e54258fdcc0164a6ed8fddeacda1b9 bf63f176c652c41d0df0b599f3c152de
VM952:14 --------- 05b757adb1f685b9c90f140aefcc150e 6b1373be53f55472142514832dd0469f 2b177576d4350dba60937384231f042e fd64b6e8d5f6bce831d59c206d23b535 d1026a12cae04cc9193f2ff44a3aa920 87ec6fc98b526d1d2abe64ad3b7fe14f bf63f176c652c41d0df0b599f3c152de
VM952:14 ---------- e985c769a468d0f3f09cb71ab5481fe6 87ec6fc98b526d1d2abe64ad3b7fe14f 856bf544fd593866b0b0c3a19f8c4f11 06e54258fdcc0164a6ed8fddeacda1b9 889c7bd62dd16088c5c3e31c4fb41080 bf63f176c652c41d0df0b599f3c152de 6b1373be53f55472142514832dd0469f
VM952:14 ----------- e985c769a468d0f3f09cb71ab5481fe6 06e54258fdcc0164a6ed8fddeacda1b9 fd64b6e8d5f6bce831d59c206d23b535 856bf544fd593866b0b0c3a19f8c4f11 2b177576d4350dba60937384231f042e 889c7bd62dd16088c5c3e31c4fb41080 d1026a12cae04cc9193f2ff44a3aa920
VM952:14 ------------ fd64b6e8d5f6bce831d59c206d23b535 856bf544fd593866b0b0c3a19f8c4f11 2b177576d4350dba60937384231f042e b39a1560417a6b0a96d64112b3743312 56434bd529129e86f20ec6079585a6c0 39840efcdfd5a485c4031a72074dd247 fa191c6b30f3c65bd22ddfd5a0fd111e
VM952:14 ------------- 2b177576d4350dba60937384231f042e d1026a12cae04cc9193f2ff44a3aa920 bf63f176c652c41d0df0b599f3c152de 05b757adb1f685b9c90f140aefcc150e 39840efcdfd5a485c4031a72074dd247 fd64b6e8d5f6bce831d59c206d23b535 e985c769a468d0f3f09cb71ab5481fe6
VM952:14 -------------- 39840efcdfd5a485c4031a72074dd247 b39a1560417a6b0a96d64112b3743312 fd64b6e8d5f6bce831d59c206d23b535 856bf544fd593866b0b0c3a19f8c4f11 e985c769a468d0f3f09cb71ab5481fe6 05b757adb1f685b9c90f140aefcc150e fa191c6b30f3c65bd22ddfd5a0fd111e
VM952:14 --------------- 856bf544fd593866b0b0c3a19f8c4f11 56434bd529129e86f20ec6079585a6c0 fa191c6b30f3c65bd22ddfd5a0fd111e d1026a12cae04cc9193f2ff44a3aa920 2b177576d4350dba60937384231f042e 06e54258fdcc0164a6ed8fddeacda1b9 b39a1560417a6b0a96d64112b3743312
VM952:14 ---------------- b39a1560417a6b0a96d64112b3743312 856bf544fd593866b0b0c3a19f8c4f11 06e54258fdcc0164a6ed8fddeacda1b9 fd64b6e8d5f6bce831d59c206d23b535 bf63f176c652c41d0df0b599f3c152de 05b757adb1f685b9c90f140aefcc150e d1026a12cae04cc9193f2ff44a3aa920
VM952:14 ----------------- fd64b6e8d5f6bce831d59c206d23b535 856bf544fd593866b0b0c3a19f8c4f11 bf63f176c652c41d0df0b599f3c152de d1026a12cae04cc9193f2ff44a3aa920 fa191c6b30f3c65bd22ddfd5a0fd111e 56434bd529129e86f20ec6079585a6c0 b39a1560417a6b0a96d64112b3743312
VM952:14 ------------------ 56434bd529129e86f20ec6079585a6c0 b39a1560417a6b0a96d64112b3743312 d1026a12cae04cc9193f2ff44a3aa920 856bf544fd593866b0b0c3a19f8c4f11 bf63f176c652c41d0df0b599f3c152de fd64b6e8d5f6bce831d59c206d23b535 05b757adb1f685b9c90f140aefcc150e
VM952:14 ------------------- fd64b6e8d5f6bce831d59c206d23b535 856bf544fd593866b0b0c3a19f8c4f11 d1026a12cae04cc9193f2ff44a3aa920 bf63f176c652c41d0df0b599f3c152de 05b757adb1f685b9c90f140aefcc150e 56434bd529129e86f20ec6079585a6c0 b39a1560417a6b0a96d64112b3743312
"shuffled slicer done"
const sl = (array, extra) => {
extra = extra || 1;
console.log('-'.repeat(extra),array[0].title, array[1].title, array[2].title, array[3].title, array[4].title, array[5].title, array[6].title);
return array.length === 7 ? "simple slicing done" : sl(array.slice(1), extra=extra+1);
};
const shuffleArray = arr => (
arr
.map(a => [Math.random(), a])
.sort((a, b) => a[0] - b[0])
.map(a => a[1])
);
const sh = (array, extra) => {
extra = extra || 1;
console.log('-'.repeat(extra),array[0].title, array[1].title, array[2].title, array[3].title, array[4].title, array[5].title, array[6].title);
return array.length === 7 ? "shuffled slicer done" : sh(shuffleArray(array).slice(1), extra=extra+1);
};
arr = $.map($.find('.tile'), (ele) => { var it = $(ele).find('svg'); return { 'val': parseInt($(it).attr('title'), 16), 'obj': ele, 'title': $(it).attr('title') }; }).sort((first,second) => first.val - second.val);
sl(arr);
sh(arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment