Created
December 14, 2015 13:59
-
-
Save mateusfreira/4214b634cd0f762389af to your computer and use it in GitHub Desktop.
cefet_tuma_1.js js
This file contains 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 fat(x) { | |
if (x == 0 || x == 1) { | |
return 1; | |
} | |
return fat(x - 1) * x; | |
} | |
var quadrado = function(x) { | |
return x * x; | |
}; | |
var numero = 1; | |
var str = "1"; | |
var array = [1, 4, 56, 6, "teste", 10.999, window]; | |
var consoleWithFor = function() { | |
for (var i = array.length - 1; i >= 0; i--) { | |
//console.log(array[i]) | |
console.log(i); | |
} | |
}; | |
var consoleWithForeachI = function() { | |
for (var i in array) { | |
//console.log(array[i]); | |
console.log(i); | |
} | |
}; | |
var consoleWithForeach = function() { | |
array.forEach(function(obj, i) { | |
console.log(obj); | |
console.log(i); | |
}); | |
}; | |
var showMyName = function() { | |
console.log("Mateus Freira!!"); | |
}; | |
var listOperation = function(list, operation) { | |
var result = 0; | |
list.forEach(function(value) { | |
result = operation(value, result); | |
}); | |
return result; | |
}; | |
var sum = function(list) { | |
return listOperation(list, function(v, r) { | |
return v + r; | |
}); | |
}; | |
var sumWithReduce = function(list) { | |
return list.reduce(function(r, v) { | |
return r + v; | |
}, 0); | |
}; | |
var I = { | |
name: "Mateus", | |
age: 26 | |
}; | |
var Person = function(_name, _age) { | |
var privateAgeSQRT = function(_age) { | |
return Math.sqrt(_age); | |
}; | |
this.age = _age; | |
age = this.age; | |
this.sqrt_age = privateAgeSQRT(_age); | |
this.getName = function() { | |
return _name; | |
}; | |
this.setName = function(name) { | |
_name = name; | |
}; | |
this.toJson = function() { | |
return JSON.stringify(this); | |
}; | |
this.showMyAge = function(_age) { | |
setInterval((function() { | |
console.log(this); | |
console.log(this.age); | |
}).bind(this), 300); | |
}; | |
}; | |
var myData = null; | |
var error = function(e) { | |
console.log('fudeu!!!!'); | |
}; | |
var getMyData = function() { | |
$.get("data.json1", function(data) { | |
myData = data; | |
myData.likes = myData.like.split(","); | |
myData.firstLike = myData.likes[0]; | |
$.get(myData.address_file, function(address) { | |
myData.address = address; | |
for (var i = myData.address.length - 1; i >= 0; i--) { | |
$.get(myData.address[i].file, function(city) { | |
myData.address[i].city = city; | |
}, error); | |
} | |
}, error ); | |
}, error); | |
}; | |
var getMyDataWithPromise = function() { | |
$.get("data.json").then(function(p) { | |
p.likes = p.like.split(","); | |
p.firstLike = p.likes[0]; | |
return p; | |
}).then(function(p) { | |
var addressPromise = $.get(p.address_file).then(function(address) { | |
p.address = address; | |
return p; | |
}); | |
return addressPromise; | |
})/*then(function(p){ | |
var all = []; | |
for (var i = p.address.length - 1; i >= 0; i--) { | |
all.push( | |
$.get(p.address[i].file).then(function(city) { | |
p.address[i].city = city; | |
})); | |
} | |
return Q.all(all); | |
})*/.then(function(p) { | |
console.log(p); | |
}).fail(error); | |
} | |
// | |
/*listOperation([3,2], function(v, r){ | |
if(r === 0){ | |
return v; | |
} | |
r *= v; | |
return r; | |
});*/ | |
//setInterval(showMyName, 3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment