### Detect Pangram

Arrays
Regular Expressions
Declarative Programming
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``````
•  1 − ``` let isPangram =str=>'abcdefghijklmnopqrstuvwxyz' ``` 2 − ``` .split`` ``` 3 − ``` .every(v => ~str.toLowerCase().indexOf(v)) ``` 1 + ```// some other ways ``` 4 4 3 + ```isPangram=s=>[...'abcdefghijklmnopqrstuvwxyz'].every(e=>s.toLowerCase().includes(e)) ``` 4 + 5 + ```isPangram=s=>[...'abcdefghijklmnopqrstuvwxyz'].every(e=>RegExp(e,'i').test(s)) ``` 6 + 7 + ```isPangram=s=>[...new Set(s.toLowerCase().match(/[a-z]/g))].length>25 ``` 8 + 9 + ```isPangram=s=>new Set(s.toLowerCase().match(/[a-z]/g)).size>25 ```

### Merge two sorted arrays from scratch

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)
}``````
•  1 − ```function mergeArrays(arrA, arrB) { ``` 2 − ``` const output = []; ``` 3 − ``` const arrAClone = [...arrA]; ``` 4 − ``` const arrBClone = [...arrB]; ``` 5 − ``` let nextSmallestA = arrAClone.shift(); ``` 6 − ``` let nextSmallestB = arrBClone.shift(); ``` 7 − ``` while (nextSmallestA !== undefined || nextSmallestB !== undefined) { ``` 8 − ``` if (nextSmallestA === undefined || nextSmallestB < nextSmallestA) { ``` 9 − ``` output.push(nextSmallestB); ``` 10 − ``` nextSmallestB = arrBClone.shift(); ``` 11 − ``` } else { ``` 12 − ``` output.push(nextSmallestA); ``` 13 − ``` nextSmallestA = arrAClone.shift(); ``` 14 − ``` } ``` 15 − ``` } ``` 16 − ``` return output; ``` 1 + ```function mergeArrays(a, b, o=[]) { ``` 2 + ``` while (a.length && b.length) ``` 3 + ``` o.push((a[0] < b[0] ? a : b).shift()) ``` 4 + ``` return o.concat(a).concat(b) ``` 17 17 ```} ```

### Unique in order - slow execution

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)``````
•  1 + ```# only works with strings, but five times faster than the original solution ``` 2 + ```import re ``` 1 1 ```def unique_in_order(iterable): ``` 2 − ``` iterable = list(iterable) ``` 3 − ``` while 1==1: ``` 4 − ``` for x in range(len(iterable)): ``` 5 − ``` if iterable[x]==iterable[x-1]: ``` 6 − ``` del iterable[x] ``` 7 − ``` break ``` 8 − ``` if x==len(iterable)-1: ``` 9 − ``` return iterable ``` 4 + ``` return re.findall(r'(.)(?!\1)', iterable) ```

### Maurer Rose

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.

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
}``````

### Find The Poisoned Apple

Same solution. Just added more tests.

### Yeeted Sentences

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``)``
•  1 − ```yeet_words=t=>t.replace(/\b\w{4,}\b/g,x=>(x<'a'?'Y':'y')+'e'.repeat(x.length-2)+'t') ``` 1 + ```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``) ```

### find highest and lowest number in a string array

Code
Diff
• ``highAndLow=a=>Math.max(...a=a.split` `)+` `+Math.min(...a)``
•  1 − ```public class Kumite { ``` 2 − ``` public static String highAndLow(String numbers) { ``` 3 − ``` String[] integerStrings = numbers.split(" "); ``` 4 − ``` int maxValue = Integer.parseInt(integerStrings[0]); ``` 5 − ``` int minValue = Integer.parseInt(integerStrings[0]); ``` 6 − ``` ``` 7 − ``` for (int i = 1; i < integerStrings.length; i++){ ``` 8 − ``` int number = Integer.parseInt(integerStrings[i]); ``` 9 − ``` if(number > maxValue){ ``` 10 − ``` maxValue = number; ``` 11 − ``` } ``` 12 − ``` if(number < minValue){ ``` 13 − ``` minValue = number; ``` 14 − ``` } ``` 15 − ``` } ``` 16 − ``` return Integer.toString(maxValue) + " " + Integer.toString(minValue); ``` 17 − ``` } ``` 18 − ```} ``` 1 + ```highAndLow=a=>Math.max(...a=a.split` `)+` `+Math.min(...a) ```

### Yeeted Sentences

Code
Diff
• ``yeet_words=t=>t.replace(/\b\w{4,}\b/g,x=>(x<'a'?'Y':'y')+'e'.repeat(x.length-2)+'t')``
•  1 − ```def yeet_words(sentence) ``` 2 − ``` yeeted = [] ``` 3 − ``` for word in sentence.split(' ') do ``` 4 − ``` new_word = nil ``` 5 − ``` l = word.match(/\w+/)[0].length ``` 6 − ``` if l > 3 ``` 7 − ``` yeet = 'y' + 'e' * (l - 2) + 't' ``` 8 − ``` new_word = word.gsub(/\w+/, yeet) ``` 9 − ``` end ``` 10 − ``` new_word = new_word.nil? ? word : new_word ``` 11 − ``` yeeted << new_word ``` 12 − ``` end ``` 13 − ``` yeeted.join(' ').capitalize() ``` 14 − ```end ``` 1 + ```yeet_words=t=>t.replace(/\b\w{4,}\b/g,x=>(x<'a'?'Y':'y')+'e'.repeat(x.length-2)+'t') ```

### Divide by 3 without division operation

Code
Diff
• ``````def dividedByThree(number):
return number and not number % 3``````
•  1 1 ```def dividedByThree(number): ``` 2 − ``` return number != 0 and not number % 3 ``` 2 + ``` return number and not number % 3 ```

### Divide by 3 without division operation

Code
Diff
• ``````// i assume this is an allowed use of "/" :)
dividedByThree=n=>/^-?0*(0*1(01*0)*1)*0*\$/.test(n.toString(2))``````
•  1 − ```def dividedByThree(number): ``` 2 − ``` if number == 0: ``` 3 − ``` return False ``` 4 − ``` return abs(number) % 3 == 0 ``` 1 + ```// i assume this is an allowed use of "/" :) ``` 2 + ```dividedByThree=n=>/^-?0*(0*1(01*0)*1)*0*\$/.test(n.toString(2)) ```

### adding 1 and -1 || invalid operation return 0 -

Code
Diff
• ``basicOp=(a,c,t)=>[...`-+*/`].includes(a)?eval(c+a+t):`Invalid Operation```
•  1 − ```function basicOp(operation, value1, value2) { ``` 2 − ``` switch (operation) { ``` 3 − ``` case '+': ``` 4 − ``` return value1 + value2; ``` 5 − ``` case '-': ``` 6 − ``` return value1 - value2; ``` 7 − ``` case '*': ``` 8 − ``` return value1 * value2; ``` 9 − ``` case '/': ``` 10 − ``` return value1 / value2; ``` 11 − ``` default: ``` 12 − ``` return 0; ``` 13 − ``` //Suppose we're adding 1 and -1. ``` 14 − ``` } ``` 15 − ```} ``` 1 + ```basicOp=(a,c,t)=>[...`-+*/`].includes(a)?eval(c+a+t):`Invalid Operation` ```

### Write a sort function

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;
}``````
•  1 − ```function sortWithoutSort(array) { ``` 2 − ``` for (let i = 0; i < array.length; i++) { ``` 3 − ``` if (i < array.length - 1) { ``` 4 − ``` if (array[i] > array[i+1]) { ``` 5 − ``` var sortVal = array.splice(i,1)[0]; ``` 6 − ``` array.splice(i+1, 0, sortVal); ``` 7 − ``` sortWithoutSort(array); ``` 8 − ``` } ``` 9 − ``` } ``` 10 − ``` } ``` 11 − ``` ``` 1 + ```function isSorted(array) { ``` 2 + ``` return array.every((e, i) => !i || array[i] >= array[i-1]) ``` 3 + ```} ``` 4 + 5 + ```function shuffle(array) { ``` 6 + ``` for (var a = 0; a < array.length; a++) { ``` 7 + ``` var b = ~~(Math.random() * array.length); ``` 8 + ``` [array[a], array[b]] = [array[b], array[a]] ``` 9 + ``` } ``` 10 + ```} ``` 11 + 12 + ```function bogoSort(array) { ``` 13 + ``` while (!isSorted(array)) ``` 14 + ``` shuffle(array); ``` 12 12 ``` return array; ``` 13 13 ```} ```

Mathematics
Algorithms
Numbers
Code
Diff
• ``average=a=>a>''?require('ramda').mean(a):a.x``
•  1 − ```average=a=>a.length?require('ramda').mean(a):a.x ``` 1 + ```average=a=>a>''?require('ramda').mean(a):a.x ```

### Invert string

Code
Diff
• ``````function invert(str) {
var combine = str.repeat(str.length)
var n = combine.length
while (--n >= 0) {
n -= str.length
}
•  1 − ```const invert = str => str.replace(/./g, (_,o,s) => s.charAt(s.length-1-o)); ``` 1 + ```function invert(str) { ``` 2 + ``` var combine = str.repeat(str.length) ``` 3 + ``` var n = combine.length ``` 4 + ``` var answer = '' ``` 5 + ``` while (--n >= 0) { ``` 6 + ``` answer += combine[n] ``` 7 + ``` n -= str.length ``` 8 + ``` } ``` 9 + ``` return answer ``` 10 + ```} ```