Skip to content

Instantly share code, notes, and snippets.

@diogocapela
Last active January 25, 2023 16:29
Show Gist options
  • Save diogocapela/20c8764a62a80ac061eb30b924f7a7eb to your computer and use it in GitHub Desktop.
Save diogocapela/20c8764a62a80ac061eb30b924f7a7eb to your computer and use it in GitHub Desktop.
My Solutions to Codewars Kata - 8kyu
My Solutions to Codewars Kata - 8kyu
function describeAge(age) {
return "You're a(n) " + (age < 13 ? "kid" : age < 18 ? "teenager" : age < 65 ? "adult" : "elderly");
}
function Person(name) {
this.name = name;
}
Person.prototype.greet = function(otherName) {
return 'Hi ' + otherName + ', my name is ' + this.name;
}
function digitize(n) {
return String(n).split('').map(Number).reverse();
}
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;
}
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;
}
}
function addFive(num) {
var total = num + 5;
return total;
}
function invert(array) {
var inverted = [];
for (var i = 0; i < array.length; i++) {
inverted.push(parseInt(-array[i]));
}
return inverted;
}
function multiply(a, b) {
return a * b;
}
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;
}
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