Handshake

in ita •  9 days ago 

let arr : string[] =["wink" ,"double blink","close your eyes", "jump"];

export function commands(num: number): string[] {
let res: string[] = [];
const binArr = num.toString(2).padStart(5, "0").split("").reverse(); // padStart garantisce la presenza di 5 digits aggiungendo 0 se necessario!
for(let i=0; i<4; i++){
if(binArr[i] === "1") res.push(arr[i]);
}
return binArr[4] === "1"? res.reverse(): res;
}

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!