1//We are trying to find a table for my speed dating group to sit at, that is the most economical for the restaurant. How many options do I have?
2
3const tableNumbers = [5, 14, 7, 10, 20, 11, 12, 15, 3]
4
5for (let i =0; i < tableNumbers.length; i++) {
6 //if the tableNumbers length can be divided by 2 (%) = and leavs a remainder of 0
7 if (tableNumbers[i] % 2 === 0) {
8 console.log(tableNumbers[i])
9 }
10}
11
1// % in JS is the remainder, not modulo
2//here is Shanimal's function for modulo operation
3// n = your number, m = number to mod by
4var mod = function (n, m) {
5 var remain = n % m;
6 return Math.floor(remain >= 0 ? remain : remain + m);
7};
8mod(5,22) // 5
9mod(25,22) // 3
10mod(-1,22) // 21
11mod(-2,22) // 20
12mod(0,22) // 0
13mod(-1,22) // 21
14mod(-21,22) // 1
15