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
| def add (num1, num2) | |
| result = num1 + num2 | |
| p "Your result is: #{result}" | |
| end | |
| def subtract (num1, num2) | |
| result = num1 - num2 | |
| p "Your result is: #{result}" | |
| end |
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
| balance = 0 | |
| def deposit(amount) | |
| balance + amount | |
| balance = balance + amount | |
| p balance | |
| end | |
| def withdraw(amount) | |
| balance = balance - amount |
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
| // First attempt: http://repl.it/51c | |
| // Bubble sort - Large numbers bubble to the top | |
| function sortArray(arr) { | |
| var tmp; | |
| for (var j = 0; j < arr.length; j++) { | |
| for (var i = 0; i < arr.length-j;i++) { | |
| if (arr[i] > arr[i+1]) { | |
| tmp = arr[i+1]; |
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 isPrime = function(number) { | |
| if (number === 1) return false; | |
| for (var i = 2; i <= number/2 ; i++) { | |
| if (number % i === 0) return false; | |
| } | |
| return true; | |
| } |
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 indexOf = function (array,element) { | |
| for (var i = 0; i < array.length; i++) { | |
| if (element === array[i]) return 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
| var flatten = function (array) { | |
| newArray = []; | |
| for (var idx1 = 0; idx1 < array.length; idx1++) { | |
| if (Array.isArray(array[idx1])) { | |
| for (var idx2 = 0; idx2 < array[idx1].length; idx2++) { | |
| newArray.push(array[idx1][idx2]); | |
| } | |
| } else { | |
| newArray.push(array[idx1]); |
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 factorial = function(num) { | |
| var product = num; | |
| for (var i = 1; i < num; i++) { | |
| product = i * product; | |
| } | |
| return product; | |
| } |
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 longestWord = function(myString) { | |
| words = myString.split(" "); | |
| longest = ""; | |
| for (var word = 0; word < words.length ; word++) { | |
| if (words[word].length > longest.length) { | |
| longest = words[word] | |
| } | |
| } | |
| return longest; |
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 sums = function(num) { | |
| myNum = 0; | |
| for (var i = 0; i <= num; i++) { | |
| myNum += i; | |
| } | |
| console.log(myNum); | |
| } | |
| sums(3); |
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
| def word_unscrambler(str, words) | |
| idx = 0 | |
| matches = [] | |
| while idx < words.length | |
| sorted = words[idx].chars.sort.join | |
| match = str.chars.sort.join | |
| word = words[idx] | |
| if sorted == match |