src/index.js
function getAxesPosition(axes, buttons) {
  if (axes.length === 10) {
    return Math.round(axes[9] / (2 / 7) + 3.5);
  }
  const [right, left, down, up] = [...buttons].reverse();
  const buttonValues = [up, right, down, left]
    .map((pressed, i) => (pressed.value ? i * 2 : false))
    .filter(val => val !== false);
  if (buttonValues.length === 0) return 8;
  if (buttonValues.length === 2 && buttonValues[0] === 0 && buttonValues[1] === 6) return 7;
  return buttonValues.reduce((prev, curr) => prev + curr, 0) / buttonValues.length;
}
function getAxesPosition(axes, buttons) {
  if (axes.length === 10) {
    return Math.round(axes[9] / (2 / 7) + 3.5);
  }
  const [right, left, down, up] = [...buttons].reverse();
  const buttonValues = [up, right, down, left]
    .map((pressed, i) => (pressed.value ? i * 2 : false))
    .filter(val => val !== false);
  if (buttonValues.length === 0) return 8;
  if (buttonValues.length === 2 && buttonValues[0] === 0 && buttonValues[1] === 6) return 7;
  return buttonValues.reduce((prev, curr) => prev + curr, 0) / buttonValues.length;
}
function getAxesPosition ( axes , buttons ) { if ( axes . length === 10 ) { return Math . round ( axes [ 9 ] / ( 2 / 7 ) + 3.5 ) ; } const [ right , left , down , up ] = [ ... buttons ] . reverse ( ) ; const buttonValues = [ up , right , down , left ] . map ( ( pressed , i ) => ( pressed . value ? i * 2 : false ) ) . filter ( val => val !== false ) ; if ( buttonValues . length === 0 ) return 8 ; if ( buttonValues . length === 2 && buttonValues [ 0 ] === 0 && buttonValues [ 1 ] === 6 ) return 7 ; return buttonValues . reduce ( ( prev , curr ) => prev + curr , 0 ) / buttonValues . length ; }
Get the axes position based based on browser.
@param {array} axes
@param {array} buttons
Get the axes position based based on browser .