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
| Array.prototype.swap = function(idx1, idx2) { | |
| let first = Math.max(idx1, idx2); | |
| let last = Math.min(idx1, idx2); | |
| this.splice(last, 0, this.splice(first, 1)[0]); | |
| }; | |
| function moveToFront(arr, idx) { | |
| arr.swap(0,idx); |
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
| // SLC -> AUS -> LAX -> JFK -> SJC | |
| let passes = [ | |
| {depart: 'JFK', arrive: 'SJC'}, | |
| {depart: 'LAX', arrive: 'JFK'}, | |
| {depart: 'AUS', arrive: 'LAX'}, | |
| {depart: 'SLC', arrive: 'AUS'} | |
| ]; | |
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
| //1, 1, 2, 3, 5, 8, 13, 21 | |
| (function() { | |
| let result = []; | |
| window.fibonacci = function(n) { | |
| if (n < 1) { | |
| throw new Error("n must be greater than 0"); | |
| } |
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
| //we have an array of objects A and an array of indexes B. Reorder objects | |
| //in array A with given indexes in array B. Do not change array A's length; | |
| var A = ['C', 'D', 'E', 'F', 'G']; | |
| var B = [3, 0, 4, 1, 2]; | |
| function resort(arr, order) { | |
| let idx=0; | |
| for(var start=0;start<arr.length;start++) { |
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 () { | |
| const SINGLES = [ | |
| 'zero', | |
| 'one', | |
| 'two', | |
| 'three', | |
| 'four', | |
| 'five', | |
| 'six', | |
| 'seven', |
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 findSqRt(target) { | |
| var upper = target, | |
| lower = 0, | |
| square=0, | |
| value=0; | |
| while(Math.abs(target-square) >= 0.00000001) { | |
| value = (upper + lower) /2; | |
| square = value * value; |
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 a = [1, {a: [2, [3]]}, 'four', [[5], [6]], [[7], 8, 9], 10]; | |
| function flatten(arr) { | |
| let idx = 0; | |
| while(idx < arr.length) { | |
| if(arr[idx] instanceof Array) { | |
| Array.prototype.splice.apply(arr, [idx, 1].concat(arr[idx])); | |
| }else { |
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.js"></script> | |
| </head> | |
| <body> | |
| <p><img src="https://securecdn.disqus.com/uploads/mediaembed/images/509/9511/original.jpg?w=128"></p> | |
| <p><img src="https://securecdn.disqus.com/uploads/mediaembed/images/509/9512/original.jpg?w=128"></p> | |
| <p><img src="https://securecdn.disqus.com/uploads/mediaembed/images/509/9513/original.jpg?w=128"></p> | |
| <p><img src="https://securecdn.disqus.com/uploads/mediaembed/images/509/9514/original.jpg?w=128"></p> |
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| </head> | |
| <body> | |
| <div id="output"></div> | |
| <hr/> | |
| <form id="myForm"> | |
| <input placeholder="Name…" type="text" id="myName"/> | |
| <input placeholder="Number…" type="number" id="myNumber"/> |
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
| // Below is a drone object with six methods. | |
| // Each method takes a callback and after some amount of time will execute that callback (for ease of testing, it will also console.log a value). | |
| // At the bottom of the page the expected output is logged. | |
| // And we invoke the chained call of the drone object. However the drone object does not yet have a chained api. | |
| // Your job is to add a chained api to the drone object by only modifying the code in the middle of the page. | |
| // A good answer should include the following criteria. | |
| // 1. Code was only added between the below comments. | |
| // 2. Each method in the chain executes only after the previous method has resolved |