This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function merge(left, right) { | |
| var merged = left.slice(0); | |
| right.forEach(function(element) { | |
| var i = merged.length - 1; | |
| var m = false; | |
| for (; i >= 0; i--) { | |
| if (merged[i] <= element) { | |
| merged.splice(i+1, 0, element); | |
| m = true; | |
| break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function quicksort(elements) { | |
| if (elements.length <= 1) { | |
| return elements; | |
| } | |
| var left = []; | |
| var right = []; | |
| var middle = Math.floor(elements.length/2); | |
| var element = null; | |
| var pivot = elements[middle]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Given an array of numbers figure out the top 5 numbers. Return the result as an array. | |
| Scoring is done thusly: | |
| * All numbers >= 1 are worth +1 point | |
| * All zeroes are worth -2 | |
| * Numbers with digits in ascending order get +5 points (e.g. [3, 4, 4, 5]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var jsondb = require("com.irlgaming.jsondb"); | |
| var collection = jsondb.factory("test","yoursharedsecrethere"); | |
| // grab all records with a value of greater than or equal to 10 for the attribute "i" | |
| // with a limit of 200 | |
| var o = collection.find({i:{$gte:10}, {limit:200}); | |
| // tuples in the result look something like: | |
| /* | |
| { |