Skip to content

Instantly share code, notes, and snippets.

View aledwassell's full-sized avatar
🏠
Working from home

Aled Wassell aledwassell

🏠
Working from home
View GitHub Profile
//Prototypal inhericance uses the the Object.create() syntax, remember this!!!!!
let Human = {
name: "David",
create: function(value){
let instance = Object.create(this);
Object.keys(value).forEach(function(key){
instance[key] = value[key];
})
return instance;
let myCurrier = (greeting) => {
return (name) => {
console.log(`${greeting} ${name}`)
}
}
let instance = myCurrier('Hello');
instance('Jack');
instance('Dave');
@aledwassell
aledwassell / app.js
Created March 4, 2018 10:57
Making a binary tree from 10 random numbers
(function() {
let tree;
function Tree(n) {
this.root = null;
}
Tree.prototype.add = function(val){
let n = new Node(val)
if(this.root === null){
@aledwassell
aledwassell / pop.js
Created February 28, 2018 14:34
In a small town the population is p0 = 1000 at the beginning of a year. The population regularly increases by 2 percent per year and moreover 50 new inhabitants per year come to live in the town. How many years does the town need to see its population greater or equal to p = 1200 inhabitants?
function nbYear(p0, percent, aug, p) {
// your code
let yearsGrown = 0;
let popNow = p0;
let amountGrown = ((popNow / 100) * percent) + 50;
while(popNow < 1200){
popNow += amountGrown;
yearsGrown++;
}
console.log('population now ', popNow)
@aledwassell
aledwassell / freecodecamp Caesar's Cipher
Last active March 23, 2017 13:45
This was the free code camps Caesar's Cipher, hard but I did it, not sure why it doesn't work though
function rot13(str) { // LBH QVQ VG!
str = str.toUpperCase().split('');
str.reduce(function(acc, item) {
var patt = /[a-zA-Z]/g;
if(patt.test(item)){
item = item.charCodeAt(0);
if(item > 77) {
@aledwassell
aledwassell / app.js
Created March 2, 2017 13:08
angular directives, using angular directives to manipulate the dom and change also using them as form validation
var myApp = angular.module('myApp', []);
myApp.controller('mainController', ['$scope', '$filter', function($scope, $filter) {
$scope.handle = "";
$scope.lowerCaseFilter = function() {
return $filter('lowercase')($scope.handle);
};
@aledwassell
aledwassell / angular JS
Created March 2, 2017 12:12
playing around with angular JS
var myApp = angular.module('myApp', []);
myApp.controller('mainController', ['$scope', '$filter', function($scope, $filter) {
$scope.handle = "";
$scope.lowerCaseFilter = function() {
return $filter('lowercase')($scope.handle);
};
@aledwassell
aledwassell / using reduce
Created February 27, 2017 23:08
using reduce to count up the number of item in an array
//items to count
const votes = [
'cow',
'sheep',
'duck',
'cow',
'cow',
'duck',
'pig',
'pig',
@aledwassell
aledwassell / Quoter
Last active January 7, 2017 05:11
Quoter
<body>
<div class="container">
<div class="jumbotron">
<div class="container">
<div class="text-center">
<h1>
Get a Random Quote
</h1>
</div>
<div id="target">
@aledwassell
aledwassell / Javascript I need to learn
Created December 31, 2016 03:26
This is the stuff I still have to get my head around in 2017
ES6: The current version of JavaScript is ES2016 (aka ES7), but a lot of developers still haven’t properly learned ES6. It’s time to learn.
Builtin methods: Learn methods for the standard data types (especially arrays, objects, strings, and numbers).
Functions & pure functions: You probably think you’ve got a great grasp of functions, but JavaScript has some tricks up its sleeves, and you’ll need to learn about pure functions to get a handle on functional programming.
Closures: Learn how JavaScript’s function scopes behave.
Callbacks: A callback is a function used by another function to signal when there is a result ready. You say, “do your job, call me when it’s done.”
Promises: A promise is a way to deal with future values. When a function returns a promise, you can attach callbacks using the .then() method to run after the promise resolves. The resolved value is passed into your callback function, e.g., doSomething().then(value => console.log(value));