フロントエンドデベロッパーのメモ

スキル: HTML/Jade/Jinja2, CSS/SCSS, JavaScript(ES6), Angular, React,Next, Redux, Node, Express, Python, Flask, Postgres, Redis, MongoDB, Kafka, Knex, SQLAlchemy, React Native, EXPO, GraphQL/Apollo, REST, AWS, Heroku, Docker, CircleCI, SCRUM, XP, Vim, TDD

The difference between European Roulette and American

const rouletteFunc = (src1, src2, num) => {
  return countDifference(makeList(src1, [], num), makeList(src2, [], num));
}

const makeList = (listSource, list, N) => {
  let sliced;
  for (let i = 0; i < listSource.length; i++) {
    if (i + N > listSource.length) {
      sliced = listSource.slice(i).concat(listSource.slice(0, N - (listSource.length - i)))
    } else {
      sliced = listSource.slice(i, i + N);
    }
    list.push(sliced.reduce((total, crr) => total + crr, 0));
  }
  return list;
}

const countDifference = (EL, AL) => {
  let count = 0;
  const ELSorted = EL.sort((first, second) => second - first)
  const ALSorted = AL.sort((first, second) => second - first)
  for (let i = 0; i < ALSorted.length; i++) {
    if (ELSorted[i] < ALSorted[i]) {
      count++;
    }
  }
  return count;
}

const european = [0, 32, 15, 19, 4, 21, 2, 25, 17, 34, 6, 27, 13, 36, 11, 30, 8, 23, 10,
  5, 24, 16, 33, 1, 20, 14, 31, 9, 22, 18, 29, 7, 28, 12, 35, 3, 26];
const american = [0, 28, 9, 26, 30, 11, 7, 20, 32, 17, 5, 22, 34, 15, 3, 24, 36, 13, 1,
  00, 27, 10, 25, 29, 12, 8, 19, 31, 18, 6, 21, 33, 16, 4, 23, 35, 14, 2];


console.log(rouletteFunc(european, american, 3));