├── Binary Converter ├── Bracket Matcher ├── Caesar Cipher ├── Consecutive ├── Dash Insert II ├── Distinct List ├── Division ├── Fibonacci Checker ├── Formatted Division ├── Look Say Sequence ├── Multiple Brackets ├── Number Encoding ├── Number Search ├── Palindrome Two ├── Prime Mover ├── Prime Time ├── README.md ├── Simple Mode ├── String Scramble ├── Swap II ├── Three Five Multiples └── Triple Double /Binary Converter: -------------------------------------------------------------------------------- 1 | //won't work if binary exceeds normal 8-bit length without spaces 2 | /*Using the JavaScript language, have the function BinaryConverter(str) 3 | return the decimal form of the binary value. For example: 4 | if 101 is passed return 5, or if 1000 is passed return 8. */ 5 | 6 | function BinaryConverter(str) { 7 | count =0; 8 | arr2 =str.split("").reverse().join(""); 9 | arr=[1,2,4,8,16,32, 64, 128]; 10 | for(var i=0; i0; i--){ 9 | if(num1%i==0 && num2%i==0){ 10 | return i; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Fibonacci Checker: -------------------------------------------------------------------------------- 1 | /*Using the JavaScript language, have the function FibonacciChecker(num) return the string yes if the number 2 | given is part of the Fibonacci sequence. This sequence is defined by: Fn = Fn-1 + Fn-2, 3 | which means to find Fn you add the previous two numbers up. 4 | The first two numbers are 0 and 1, then comes 1, 2, 3, 5 etc. If num is not in the Fibonacci 5 | sequence, return the string no. */ 6 | 7 | function FibonacciChecker(num) { 8 | if(num===2||num===3){ 9 | return "yes"; 10 | } 11 | var num1=0; 12 | var num2=1; 13 | var num3=1; 14 | for(var i=0; i<=num; i++){ 15 | if(num1===num){return "yes";} 16 | num1 = num2; 17 | num2 = num3; 18 | num3 = num1+num2; 19 | } 20 | return "no"; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Formatted Division: -------------------------------------------------------------------------------- 1 | //works for most cases, but need to figure out the significant digits 2 | 3 | /*Using the JavaScript language, have the function FormattedDivision(num1,num2) 4 | take both parameters being passed, divide num1 by num2, and return the result as a 5 | string with properly formatted commas and 4 significant digits after the decimal place. 6 | For example: if num1 is 123456789 and num2 7 | is 10000 the output should be "12,345.6789". The output must contain a number in the one's place even if it is a zero. */ 8 | 9 | function FormattedDivision(num1,num2) { 10 | var div = parseFloat(num1/num2); 11 | var arr = div.toString().split(""); 12 | var len = arr.length-1; 13 | var dot =0; 14 | for(var i=len; i>0; i--){ 15 | if(arr[i]==="."){ 16 | dot++; 17 | } 18 | } 19 | if(dot===0){ 20 | arr.push(".", 0, 0, 0, 0); 21 | } 22 | for(var i=len; i>0; i--){ 23 | if(arr[i+3]==="."){ 24 | arr.splice(i, 0, ","); 25 | } 26 | if(arr[i+3]===","){ 27 | arr.splice(i, 0, ","); 28 | } 29 | } 30 | return arr.join(""); 31 | } 32 | -------------------------------------------------------------------------------- /Look Say Sequence: -------------------------------------------------------------------------------- 1 | /*Using the JavaScript language, have the function LookSaySequence(num) 2 | take the num parameter being passed and return the next number in the sequence 3 | according to the following rule: to generate the next number in a sequence read 4 | off the digits of the given number, counting the number of digits in groups of 5 | the same digit. For example, the sequence beginning with 1 would be: 1, 11, 21, 1211, ... 6 | The 11 comes from there being "one 1" before it and the 21 7 | comes from there being "two 1's" before it. So your program should return the next number in the sequence given num. */ 8 | 9 | function LookSaySequence(num) { 10 | var arr = num.toString().split(""); 11 | var arr2=[]; 12 | for(var i=0; icount2){ 18 | mode = arr[i]; 19 | count2 = count; 20 | count =0; 21 | } 22 | } 23 | } 24 | if(count2==0){ 25 | return -1; 26 | } 27 | return mode; 28 | } 29 | -------------------------------------------------------------------------------- /String Scramble: -------------------------------------------------------------------------------- 1 | //This works for almost all inputs, working to fix issues 2 | /*Using the JavaScript language, have the function StringScramble(str1,str2) 3 | take both parameters being passed and return the string true if a portion of str1 4 | characters can be rearranged to match str2, otherwise return the string false. For example: if str1 is "rkqodlw" 5 | and str2 is "world" the output should return true. Punctuation and symbols will not be entered with the parameters. */ 6 | 7 | function StringScramble(str1,str2) { 8 | var arr=[]; 9 | for(i=0; i1; i--){ 10 | if(i%5===0 || i%3===0){ 11 | arr.push(i); 12 | } 13 | } 14 | for(var i=0; i