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
| /* | |
| You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments. | |
| */ | |
| function destroyer(arr) { | |
| let len =arguments.length; | |
| let indexArr = []; | |
| let arrCopy = arr.concat([]); //do not change the input array | |
| if(len > 1){ | |
| for(let i=0; i<arrCopy.length; i++){ |
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 sym(args) { | |
| let len = arguments.length; | |
| let outArr = []; | |
| //delete the repeated element in each argument | |
| for(let i=0; i<len; i++){ | |
| if(arguments[i].length <= 1){ | |
| arguments[i] = arguments[i]; | |
| } | |
| for(let j=arguments[i].length-1; j>=1; j--){ | |
| for(let k=j-1; k>=0; k--){ |
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 moveDisk(n, source, buffer, destination){ | |
| if(n>=1){ | |
| moveDisk(n-1, source, destination, buffer); | |
| console.log("Move one disk from " + source + " to " + destination); | |
| moveDisk(n-1, buffer, source, destination); | |
| }else{ | |
| return; | |
| } | |
| } |
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> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <meta charset="utf-8"> | |
| <title>JS Calculator</title> | |
| <!--<link rel="stylesheet" type="text/css" href="calculator.css"> --> | |
| <style> | |
| div table{ |
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 called = 0; | |
| var hash = (string) => { | |
| called++; | |
| var hash = 0; | |
| for (var i = 0; i < string.length; i++) { hash += string.charCodeAt(i); } | |
| return hash; | |
| }; | |
| var HashTable = function() { | |
| this.collection = {}; | |
| // change code below this line |
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 LinkedList() { | |
| var length = 0; | |
| var head = null; | |
| var Node = function(element){ | |
| this.element = element; | |
| this.next = null; | |
| }; | |
| this.head = function(){ |
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 Node = function(data, prev) { | |
| this.data = data; | |
| this.prev = prev; | |
| this.next = null; | |
| }; | |
| var DoublyLinkedList = function() { | |
| this.head = null; | |
| this.tail = null; | |
| // change code below this line | |
| length = 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
| var displayTree = (tree) => console.log(JSON.stringify(tree, null, 2)); | |
| function Node(value) { | |
| this.value = value; | |
| this.left = null; | |
| this.right = null; | |
| } | |
| function BinarySearchTree() { | |
| this.root = null; | |
| this.add = function(val) { |
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 largestPalindromeProduct(n) { | |
| // Good luck! | |
| let i = 10**n-1; | |
| let k = 10**(n-1); | |
| while (i >= k){ | |
| let j = 10**n-1; | |
| while(j >= k){ | |
| console.log("attempt", i, j, i*j); |
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 isPalindrome(s) { | |
| let len = s.length; | |
| for (let i = 0; i < Math.floor(len / 2); i++) { | |
| if (s.charAt(i) !== s.charAt(len - i - 1)) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } |
OlderNewer