Last active
May 7, 2022 19:00
-
-
Save nikonov91-dev/b95bf808e23732f1b32e3d743f625982 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
function survivors(movs: number[], pws: number[][]): number[] { | |
const final:number[] = pws.reduce((acc:number[],n:number[],jj:number):number[] => { | |
const sum = n.reduce((s,nxt) => s + nxt, movs[jj]); | |
console.log(sum,jj, n.length-1, movs[jj]) | |
const checkMovement = (n.length === 0 && sum > 0) || (sum-n.length > 0); | |
return checkMovement ? [...acc, jj] : acc | |
}, []) | |
return final | |
} | |
const r = survivors([2,3,0],[ | |
[0], [0,2], [1]]); | |
console.log('result: ' + r); | |
//https://www.codewars.com/kata/60a516d70759d1000d532029/train/typescript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment