Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function atLeastHalf(array) {
  let res = 0;
  const half = Math.ceil(array.length / 2)
  for (let i = 0; i < Math.pow(2, array.length); i++) {
    if(bitsOn(i) < half) {
      let col = 1
      for(let c = 0; c < array.length; c++) {
        col *= ((i&1<<c) ? array[c] : 1 - array[c])
      }
      res += col
    }
  }
  return 1 - res
  function bitsOn(number) {
    let value = 0
    for(let i = 0; i < 8; i++) {
      value += number&1<<i?1:0
    }
    return value
    }
}
console.assert(atLeastHalf([0.1, 0.2, 0.3, 0.4]) == 0.2572)
console.assert(atLeastHalf([0.9, 0.9, 0.9, 0.9, 0.9]) == 0.99144)
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers