-
-
Save diogocapela/20c8764a62a80ac061eb30b924f7a7eb to your computer and use it in GitHub Desktop.
My Solutions to Codewars Kata - 8kyu
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
My Solutions to Codewars Kata - 8kyu |
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 describeAge(age) { | |
return "You're a(n) " + (age < 13 ? "kid" : age < 18 ? "teenager" : age < 65 ? "adult" : "elderly"); | |
} |
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 Person(name) { | |
this.name = name; | |
} | |
Person.prototype.greet = function(otherName) { | |
return 'Hi ' + otherName + ', my name is ' + this.name; | |
} |
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 digitize(n) { | |
return String(n).split('').map(Number).reverse(); | |
} |
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 countPositivesSumNegatives(input) { | |
var sumNeg = 0; | |
var countPos = 0; | |
var final = []; | |
if (input === null || input.length === 0) { | |
return []; | |
} | |
for (var i = 0; i < input.length; i++) { | |
if (input[i] < 0) { | |
sumNeg = sumNeg + input[i]; | |
} else if (input[i] > 0) { | |
countPos = countPos +1; | |
} | |
} | |
final[0] = countPos; | |
final[1] = sumNeg; | |
return final; | |
} |
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
class Person { | |
constructor(firstName = 'John', lastName = 'Doe', age = 0, gender = 'Male') { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
this.age = age; | |
this.gender = gender; | |
} | |
sayFullName() { | |
return this.firstName + ' ' + this.lastName; | |
} | |
static greetExtraTerrestrials(raceName) { | |
return 'Welcome to Planet Earth ' + raceName; | |
} | |
} |
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 addFive(num) { | |
var total = num + 5; | |
return total; | |
} |
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 invert(array) { | |
var inverted = []; | |
for (var i = 0; i < array.length; i++) { | |
inverted.push(parseInt(-array[i])); | |
} | |
return inverted; | |
} |
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 multiply(a, b) { | |
return a * b; | |
} |
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
var number = function(busStops){ | |
var people = 0; | |
for (var i = 0; i < busStops.length; i++) { | |
people = people + busStops[i][0] - busStops[i][1]; | |
} | |
return people; | |
} |
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 simpleMultiplication(x){ | |
if (x % 2 === 0) { | |
x = x * 8; | |
} else { | |
x = x * 9; | |
} | |
return x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment