guilhermeprokisch / guilherme

0 stars 0 forks source link

javascript #200

Open cogitable[bot] opened 2 years ago

cogitable[bot] commented 2 years ago
Mention in AlgoExpert #194

nonConstructibleChange ts typescript e javascript o sort padrão é gramatical. Por isso tem que se colocar o parametro

 array.sort((x,y) => x-y )
export function nonConstructibleChange(coins: number[]) {
  coins.sort((x,y) => x-y)
    let currentChangeCreated = 0
    for (let i=0; i < coins.length; i++){
        if (coins[i] > currentChangeCreated + 1){
            return currentChangeCreated + 1
        } 
        currentChangeCreated += coins[i]
    }
    return currentChangeCreated + 1
}