I spent probably 5 times more time on this exercise than I have on any other non design related one - and partly because I spent a lot of time trying to do a series of prime factorials by looping through things and it turns out that isn’t that way. But since it’s the kind of thing I wouldn’t be able to sleep until I finished (cause it’s 12:17 here and I’ll be up at 5:30) i kind of had to keep pushing at it.

Many unhelpful people on the chat were discouraging but one person reminded me of how I could use objects, and while this may be ‘smelly and dirty’ at least it’s mine.

```
function smallestCommons(arr) {
arr = arr.sort(function(a,b){
return a-b;
});
var testArray = [];
for (i=arr[0]; i<= arr[arr.length-1]; i++) {
if (i !== 1) {
testArray.push(i);
}
}
var result = 1;
var primes = [];
for(i=2; i<= arr[arr.length-1]; i++) {
var count = 0;
if (i<4) {
primes.push(i);
} else {
for(j=0; j<primes.length; j++) {
if (i%primes[j] === 0) {
count = 1;
break;
}
} if (count === 0) {
primes.push(i);
}
}
}
var obj = {};
for (i=0; i<testArray.length; i++) {
var x = testArray[i];
for(j=0; j<primes.length; j++) {
var y=0;
var z = primes[j];
console.log(z);
if (!obj.hasOwnProperty(z)) {
obj[z] = 0;
}
while(x%primes[j] === 0) {
y ++;
x/= primes[j];
}
if (obj[primes[j]] < y ) { obj[primes[j]] = y; }
if (x == 1) { continue; }
}
}
var test = Object.keys(obj);
for (i=0; i<test.length; i++) {
if (obj[test[i]] > 0) {
var c = 1;
while(c <= obj[test[i]]) {
result *= parseInt(test[i]);
c++;
}
}
}
return result;
}
smallestCommons([1,13]);
```