Ad
Strings

ez

Code
Diff
  • isUnique=s=>new Set(s).size==s.length
    • isUnique=s=>new Set(s).size===s.length
    • isUnique=s=>new Set(s).size==s.length

Given two booleans, make a function XOR, that returns whether those booleans are different, in 35 characters or less. Your function can't use != and == - that would be too easy.

XOR=(a,b)=>!!((a+b)%2)

This will return a different value every time you call it, looping through numbers 1-4.

val = 0;
iter = () => {
  val++;
  if(val>4) val-=4;
  return val;
}

Write a function to rotate a two-dimensional array 90 degrees clockwise, and name it rotateArray. The array is always a perfect rectangle.

const rotateArray = m => m[0].map((_,i)=>m.map(r=>r[i]).reverse());
// todo: make it work for empty arrays

Come up with a creative way to replicate the functionality of Math.sign() (extra credits for not using the Math module at all).

The function should be named numberSign, and it should return +1 for positive numbers, -1 for negative, and 0 for 0.

const numberSign = x => x/Math.abs(x) || 0;