Skip to content

Instantly share code, notes, and snippets.

@nikonov91-dev
Last active May 7, 2022 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikonov91-dev/b95bf808e23732f1b32e3d743f625982 to your computer and use it in GitHub Desktop.
Save nikonov91-dev/b95bf808e23732f1b32e3d743f625982 to your computer and use it in GitHub Desktop.
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