diff --git a/amidakuji/index.js b/amidakuji/index.js new file mode 100644 index 0000000..f72063d --- /dev/null +++ b/amidakuji/index.js @@ -0,0 +1,12 @@ +// https://www.codewars.com/kata/amidakuji/javascript + +function amidakuji(arr) { + const swap = (arr, ai, bi) => [arr[ai], arr[bi]] = [arr[bi], arr[ai]]; + const res = new Array(arr[0].length+1).fill(0).map((_,i)=>i); + arr.map((row, ri) => { + [...row].map((d, di) => { + d === '1' && swap(res, di, di + 1); + }); + }); + return res; +}