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
| // Bonfire: Pig Latin | |
| // Author: @tylerl-uxai | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-pig-latin | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function translate(str) { | |
| var regex = /[aeiou]/gi; | |
| if (str[0].match(regex)){ | |
| return str + "way"; | |
| } else if (str[1].match(regex)){ |
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
| // Bonfire: Search and Replace | |
| // Author: @tylerl-uxai | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-search-and-replace | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| // Rewritten by myself with the help of https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Bonfire-Search-and-Replace | |
| function myReplace(str, before, after) { | |
| var i = str.indexOf(before); | |
| if (str[i] == str[i].toUpperCase()){ |
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
| // Bonfire: Where art thou | |
| // Author: @tylerl-uxai | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-where-art-thou | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| // Rewritten myself with help from https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Bonfire-Where-art-thou | |
| function where(collection, source) { | |
| // speed test | |
| var keys = Object.keys( source ); // returns the keys to the variable | |
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
| // Bonfire: Roman Numeral Converter | |
| // Author: @tylerl-uxai | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-roman-numeral-converter | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| // re-wrote by myself with the aid of http://wulkan.me/bonfire-roman-numeral-converter/ | |
| function convert(num) { | |
| var romanNumerals = '', | |
| decimals = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1], | |
| numerals = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', '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
| // Bonfire: Diff Two Arrays | |
| // Author: @tylerl-uxai | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-diff-two-arrays | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| // with the help of http://wulkan.me/bonfire-diff-two-arrays/ and https://github.com/pfilippi24 | |
| function diff(arr1, arr2) { | |
| // Same, same; but different. | |
| return arr1.concat(arr2).filter(function(val){ | |
| return !(arr1.indexOf(val)>=0 && arr2.indexOf(val) >=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
| function p = predict(theta, X) | |
| %PREDICT Predict whether the label is 0 or 1 using learned logistic | |
| %regression parameters theta | |
| % p = PREDICT(theta, X) computes the predictions for X using a | |
| % threshold at 0.5 (i.e., if sigmoid(theta'*x) >= 0.5, predict 1) | |
| m = size(X, 1); % Number of training examples | |
| % You need to return the following variables correctly | |
| p = zeros(m, 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
| Running Gradient Descent ... | |
| ans = | |
| 32.0727 | |
| Theta found by gradient descent: 0.000000 0.000000 | |
| For population = 35,000, we predict a profit of 0.000000 | |
| For population = 70,000, we predict a profit of 0.000000 |
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 J = computeCost(X, y, theta) | |
| %COMPUTECOST Compute cost for linear regression | |
| % J = COMPUTECOST(X, y, theta) computes the cost of using theta as the | |
| % parameter for linear regression to fit the data points in X and y | |
| % Initialize some useful values | |
| m = length(y); % number of training examples | |
| % You need to return the following variables correctly |
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 [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters) | |
| %GRADIENTDESCENT Performs gradient descent to learn theta | |
| % theta = GRADIENTDESENT(X, y, theta, alpha, num_iters) updates theta by | |
| % taking num_iters gradient steps with learning rate alpha | |
| % Initialize some useful values | |
| m = length(y); % number of training examples | |
| J_history = zeros(num_iters, 1); | |
| for iter = 1:num_iters |