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 each(coll, f) { | |
| // if (Array.isArray(coll)) { | |
| // for (var i = 0; i < coll.length; i++) { | |
| // f(coll[i], i); | |
| // } | |
| // } else { | |
| // for (var key in coll) { | |
| // f(coll[key], key); | |
| // } | 
  
    
      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 each(array, func) { | |
| // for (var i = 0; i < array.length; i++) { | |
| // func(array[i]); | |
| // } | |
| // } | |
| // var arr = [1, 2, 3, 4]; | |
| // function sumSquares(numbers) { | |
| // var total = 0; | |
| // each(numbers, function(x) { | |
| // total += x * x; | 
  
    
      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 each(array, func) { | |
| // for (var i = 0; i < array.length; i++) { | |
| // func(array[i]); | |
| // } | |
| // } | |
| // var arr = [1, 2, 3, 4]; | |
| // function sumSquares(numbers) { | |
| // var total = 0; | |
| // each(numbers, function(x) { | |
| // total += x * x; | 
  
    
      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 coinFlip() { | |
| //get either 0 or 1 randomly | |
| var random = Math.floor(Math.random() * 2); | |
| //if the number is 0 | |
| if (random === 0) { | |
| //return head | |
| return 'head'; | |
| //if the number is 1 | |
| } else { | |
| //return tail | 
  
    
      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 toggleCase(string) { | |
| //input = string | |
| //split string's characters so we can work with them individualy | |
| var strArr = string.split(''); | |
| //define a variable to keep toggled characters | |
| var toggled = []; | |
| //loop through each element in the string array | |
| for (var i = 0; i < strArr.length; i++) { | |
| //if it is a lower case | |
| if (strArr[i] === strArr[i].toLowerCase()) { | 
  
    
      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 calculateTotalWithTax (subTotal) { | |
| var tax= subTotal * (9.75 / 100); | |
| var withTax = subTotal + tax; | |
| return withTax; | |
| } | |
| // calculateTotalWithTax(250); //274.375 | |
| // calculateTotalWithTax(500); //548.75 | |
| function countBy (number) { | 
  
    
      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
    
  
  
    
  | // Flip every pair of characters in a string. | |
| // Example: | |
| // var input = 'check out how interesting this problem is, it\'s insanely interesting!'; | |
| // var output = flipPairs(input); | |
| // console.log(output); // --> hcce kuo toh wnietertsni ghtsip orlbmei ,si 't sniasenyli tnreseitgn! | |
| // input = string | |
| // output = string | 
NewerOlder