Last active
October 10, 2017 03:23
-
-
Save mdamaceno/756c1aef6b7c82344e21d0bf76ae4789 to your computer and use it in GitHub Desktop.
Training JS
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
'use strict' | |
let walk = function() { | |
return 'Walking...' | |
} | |
let talk = function() { | |
return this.sound | |
} | |
let smell = function() { | |
return 'Smelling...' | |
} | |
let travel = function() { | |
return 'Traveling...' | |
} | |
let develop = function() { | |
return 'Coding...' | |
} | |
let teach = function() { | |
return 'Teaching...' | |
} | |
let dog = Object.create({ | |
name: 'Pitico', | |
sound: 'Auau', | |
talk, | |
smell | |
}) | |
let person1 = { | |
walk, | |
talk, | |
smell, | |
travel | |
} | |
let person2 = { | |
name: 'Marco', | |
sound: function(name) { | |
return `Hahahaha! ${name}` | |
}, | |
walk, | |
talk, | |
smell, | |
travel, | |
develop | |
} | |
console.log(person1) | |
console.log(`${dog.name}: `, `${dog.talk()}`) | |
console.log(`${person1.name}: `, person1.talk()) | |
console.log(`${person2.name}: `, person2.talk()(person2.name), person2.develop()) | |
function range(start, end) { | |
start = parseInt(start) | |
end = parseInt(end) | |
let array | |
let aux | |
if(start < end) { | |
array = [start] | |
aux = start | |
while(aux < end) { | |
array.push(aux + 1) | |
aux++ | |
} | |
} else { | |
array = [start] | |
aux = start | |
while(aux > end) { | |
array.push(aux - 1) | |
aux-- | |
} | |
} | |
return array | |
} | |
function betterRange(start, end) { | |
return new Array(Math.abs((start) - (end)) + 1) | |
.fill() | |
.map((d, i) => { | |
if(start < end) { | |
return i +(start) | |
} | |
return i +(end) | |
}) | |
.sort((a, b) => { | |
if (start > end) { | |
return b - a | |
} | |
return a - b | |
}) | |
} | |
console.log(range(55, 9)) | |
function numberRange (start, end) { | |
return new Array(1 + end - start).fill().map((d, i) => i + start); | |
} | |
console.log(new Array(1 + 10 - 2).fill().map((d, i) => i + 2)) | |
let sum = function(item) { | |
return item.reduce(function(a, b) { | |
return a + b | |
}) | |
} | |
console.log(range(10, 55).find(element => element === 10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment