Games
Fundamentals
const whoShouldServe = ($scoreLeft, $scoreRight, $servesCount) => ~~(($scoreLeft + $scoreRight) / $servesCount) % 2 === 0 ? 'first' : 'second'
function whoShouldServe($scoreLeft, $scoreRight, $servesCount) {return ~~(($scoreLeft + $scoreRight) / $servesCount) % 2 === 0 ? 'first' : 'second';};- const whoShouldServe = ($scoreLeft, $scoreRight, $servesCount) => ~~(($scoreLeft + $scoreRight) / $servesCount) % 2 === 0 ? 'first' : 'second'
function prime_checker(n) { if (n <= 1) return false for (let i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0) return false } return true }
function prime_checker(n){if(n <= 1){return false;}for(var i = 2; i <= Math.sqrt(n); i++){if(n%i == 0){return false;}}return true;- function prime_checker(n) {
- if (n <= 1) return false
- for (let i = 2; i <= Math.sqrt(n); i++) {
- if (n % i == 0) return false
- }
- return true
- }
Strings
Parsing
const stripEnds = (s, prefix, suffix) => s.replace(new RegExp(`[${prefix}${suffix}]`, 'gi'), '')
function stripEnds(s, prefix, suffix) {return s.replace(new RegExp(`[${prefix}${suffix}]`, 'gi'), '');}- const stripEnds = (s, prefix, suffix) => s.replace(new RegExp(`[${prefix}${suffix}]`, 'gi'), '')