Ad
Arrays
Data Types
Regular Expressions
Declarative Programming
Advanced Language Features
Programming Paradigms
Fundamentals
Strings
Code
Diff
  • // some other ways
    
    isPangram=s=>[...'abcdefghijklmnopqrstuvwxyz'].every(e=>s.toLowerCase().includes(e))
    
    isPangram=s=>[...'abcdefghijklmnopqrstuvwxyz'].every(e=>RegExp(e,'i').test(s))
    
    isPangram=s=>[...new Set(s.toLowerCase().match(/[a-z]/g))].length>25
    
    isPangram=s=>new Set(s.toLowerCase().match(/[a-z]/g)).size>25
    • let isPangram =str=>'abcdefghijklmnopqrstuvwxyz'
    • .split``
    • .every(v => ~str.toLowerCase().indexOf(v))
    • // some other ways
    • isPangram=s=>[...'abcdefghijklmnopqrstuvwxyz'].every(e=>s.toLowerCase().includes(e))
    • isPangram=s=>[...'abcdefghijklmnopqrstuvwxyz'].every(e=>RegExp(e,'i').test(s))
    • isPangram=s=>[...new Set(s.toLowerCase().match(/[a-z]/g))].length>25
    • isPangram=s=>new Set(s.toLowerCase().match(/[a-z]/g)).size>25
Code
Diff
  • function mergeArrays(a, b, o=[]) {
      while (a.length && b.length)
        o.push((a[0] < b[0] ? a : b).shift())
      return o.concat(a).concat(b)
    }
    • function mergeArrays(arrA, arrB) {
    • const output = [];
    • const arrAClone = [...arrA];
    • const arrBClone = [...arrB];
    • let nextSmallestA = arrAClone.shift();
    • let nextSmallestB = arrBClone.shift();
    • while (nextSmallestA !== undefined || nextSmallestB !== undefined) {
    • if (nextSmallestA === undefined || nextSmallestB < nextSmallestA) {
    • output.push(nextSmallestB);
    • nextSmallestB = arrBClone.shift();
    • } else {
    • output.push(nextSmallestA);
    • nextSmallestA = arrAClone.shift();
    • }
    • }
    • return output;
    • }
    • function mergeArrays(a, b, o=[]) {
    • while (a.length && b.length)
    • o.push((a[0] < b[0] ? a : b).shift())
    • return o.concat(a).concat(b)
    • }
Code
Diff
  • # only works with strings, but five times faster than the original solution
    import re
    def unique_in_order(iterable):
        return re.findall(r'(.)(?!\1)', iterable)
    • # only works with strings, but five times faster than the original solution
    • import re
    • def unique_in_order(iterable):
    • iterable = list(iterable)
    • while 1==1:
    • for x in range(len(iterable)):
    • if iterable[x]==iterable[x-1]:
    • del iterable[x]
    • break
    • if x==len(iterable)-1:
    • return iterable
    • return re.findall(r'(.)(?!\1)', iterable)

Just seeing if I can get the canvas element to work.

The best way to see the canvasses is to hit Fork, then Run, then look at the test logs.

More information about these images:
https://en.wikipedia.org/wiki/Maurer_rose

function maurerRose(n, d, length) {
  length /= 2
  var locations = []
  for (var i = 0; i <= 360; i++) {
    var k = i * d * Math.PI / 180
    var r = Math.sin(n * k) * length
    var a = r * Math.cos(k) + length
    var b = r * Math.sin(k) + length
    locations.push([Math.round(a), Math.round(b)]) 
  }
  return locations
}

Same solution. Just added more tests.

yeeted it

Code
Diff
  • yeet_words=t=>t.replace(/\b\w{4,}\b/g,x=>[...'y'+'e'.repeat(x.length-2)+'t'].map((e,i)=>x[i]<'a'?e.toUpperCase():e).join``)
    • yeet_words=t=>t.replace(/\b\w{4,}\b/g,x=>(x<'a'?'Y':'y')+'e'.repeat(x.length-2)+'t')
    • yeet_words=t=>t.replace(/\b\w{4,}\b/g,x=>[...'y'+'e'.repeat(x.length-2)+'t'].map((e,i)=>x[i]<'a'?e.toUpperCase():e).join``)
Code
Diff
  • highAndLow=a=>Math.max(...a=a.split` `)+` `+Math.min(...a)
    • public class Kumite {
    • public static String highAndLow(String numbers) {
    • String[] integerStrings = numbers.split(" ");
    • int maxValue = Integer.parseInt(integerStrings[0]);
    • int minValue = Integer.parseInt(integerStrings[0]);
    • for (int i = 1; i < integerStrings.length; i++){
    • int number = Integer.parseInt(integerStrings[i]);
    • if(number > maxValue){
    • maxValue = number;
    • }
    • if(number < minValue){
    • minValue = number;
    • }
    • }
    • return Integer.toString(maxValue) + " " + Integer.toString(minValue);
    • }
    • }
    • highAndLow=a=>Math.max(...a=a.split` `)+` `+Math.min(...a)
Code
Diff
  • yeet_words=t=>t.replace(/\b\w{4,}\b/g,x=>(x<'a'?'Y':'y')+'e'.repeat(x.length-2)+'t')
    • def yeet_words(sentence)
    • yeeted = []
    • for word in sentence.split(' ') do
    • new_word = nil
    • l = word.match(/\w+/)[0].length
    • if l > 3
    • yeet = 'y' + 'e' * (l - 2) + 't'
    • new_word = word.gsub(/\w+/, yeet)
    • end
    • new_word = new_word.nil? ? word : new_word
    • yeeted << new_word
    • end
    • yeeted.join(' ').capitalize()
    • end
    • yeet_words=t=>t.replace(/\b\w{4,}\b/g,x=>(x<'a'?'Y':'y')+'e'.repeat(x.length-2)+'t')
Code
Diff
  • def dividedByThree(number):
        return number and not number % 3
    • def dividedByThree(number):
    • return number != 0 and not number % 3
    • return number and not number % 3
Code
Diff
  • // i assume this is an allowed use of "/" :)
    dividedByThree=n=>/^-?0*(0*1(01*0)*1)*0*$/.test(n.toString(2))
    • def dividedByThree(number):
    • if number == 0:
    • return False
    • return abs(number) % 3 == 0
    • // i assume this is an allowed use of "/" :)
    • dividedByThree=n=>/^-?0*(0*1(01*0)*1)*0*$/.test(n.toString(2))
Code
Diff
  • basicOp=(a,c,t)=>[...`-+*/`].includes(a)?eval(c+a+t):`Invalid Operation`
    • function basicOp(operation, value1, value2) {
    • switch (operation) {
    • case '+':
    • return value1 + value2;
    • case '-':
    • return value1 - value2;
    • case '*':
    • return value1 * value2;
    • case '/':
    • return value1 / value2;
    • default:
    • return 0;
    • //Suppose we're adding 1 and -1.
    • }
    • }
    • basicOp=(a,c,t)=>[...`-+*/`].includes(a)?eval(c+a+t):`Invalid Operation`

I have chosen to implement the best sorting algorithm, which is bogosort. I use bogosort in all of my production code and I've collected quotes from my clients:

"It has performance unlike any other algorithm."

"I've never seen a sorting algorithm do that before."

"After I input a million records and saw the code running, the tears just streamed down my face."

"I tried bogosort and then several weeks later I was recommending it to all my competitors."

Code
Diff
  • function isSorted(array) {
      return array.every((e, i) => !i || array[i] >= array[i-1])
    }
    
    function shuffle(array) {
      for (var a = 0; a < array.length; a++) {
        var b = ~~(Math.random() * array.length);
        [array[a], array[b]] = [array[b], array[a]]
      }
    }
    
    function bogoSort(array) {
      while (!isSorted(array))
        shuffle(array);
      return array;
    }
    • function sortWithoutSort(array) {
    • for (let i = 0; i < array.length; i++) {
    • if (i < array.length - 1) {
    • if (array[i] > array[i+1]) {
    • var sortVal = array.splice(i,1)[0];
    • array.splice(i+1, 0, sortVal);
    • sortWithoutSort(array);
    • }
    • }
    • }
    • function isSorted(array) {
    • return array.every((e, i) => !i || array[i] >= array[i-1])
    • }
    • function shuffle(array) {
    • for (var a = 0; a < array.length; a++) {
    • var b = ~~(Math.random() * array.length);
    • [array[a], array[b]] = [array[b], array[a]]
    • }
    • }
    • function bogoSort(array) {
    • while (!isSorted(array))
    • shuffle(array);
    • return array;
    • }
Mathematics
Algorithms
Logic
Numbers
Data Types
Code
Diff
  • average=a=>a>''?require('ramda').mean(a):a.x
    • average=a=>a.length?require('ramda').mean(a):a.x
    • average=a=>a>''?require('ramda').mean(a):a.x
Code
Diff
  • function invert(str) {
      var combine = str.repeat(str.length)
      var n = combine.length
      var answer = ''
      while (--n >= 0) {
        answer += combine[n]
        n -= str.length
      }
      return answer
    }
    • const invert = str => str.replace(/./g, (_,o,s) => s.charAt(s.length-1-o));
    • function invert(str) {
    • var combine = str.repeat(str.length)
    • var n = combine.length
    • var answer = ''
    • while (--n >= 0) {
    • answer += combine[n]
    • n -= str.length
    • }
    • return answer
    • }
Arrays
Data Types
Algorithms
Logic
Data

This is the same as the reference solution, but has a range of tests, so anyone can use this to check the speed of their solution. In the comments below I have compared the speed of the submitted solutions.

Loading more items...