Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Task5/question1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// http://www.codewars.com/kata/array-helpers

Array.prototype.square = function() {
let arr = this;
let tempArr = [];
for (i = 0; i < arr.length; i++) {
tempArr.push(arr[i] * arr[i]);
}
return tempArr;
}

Array.prototype.cube = function() {
let arr = this;
let tempArr = [];
for (i = 0; i < arr.length; i++) {
tempArr.push(arr[i] * arr[i] * arr[i]);
}
return tempArr;
}

Array.prototype.sum = function() {
let arr = this;
let total = 0;
for (i = 0; i < arr.length; i++) {
total += arr[i];
}
return total;
}

Array.prototype.average = function() {
let arr = this;
let total = 0;
console.log(this);
for (i = 0; i < arr.length; i++) {
total += arr[i];
}
return arr.length > 0 ? total / arr.length : NaN;
}

Array.prototype.even = function() {
let arr = this;
let tempArr = [];
for (i = 0; i < arr.length; i++) {
if (arr[i] % 2 == 0) {
tempArr.push(arr[i]);
}
}
return tempArr;
}

Array.prototype.odd = function() {
let arr = this;
let tempArr = [];
for (i = 0; i < arr.length; i++) {
if (arr[i] % 2 != 0) {
tempArr.push(arr[i]);
}
}
return tempArr;
}
13 changes: 13 additions & 0 deletions Task5/question2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// http: //www.codewars.com/kata/extract-nested-object-reference

Object.prototype.hash = function(string) {
let strArr = string.split(".");
let tempObj = this;
for (let i = 0; i < strArr.length; i++) {\
tempObj = tempObj[strArr[i]];
if (tempObj == undefined) {
return undefined;
}
}
return tempObj;
}
5 changes: 5 additions & 0 deletions Task5/question3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// http://www.codewars.com/kata/new-with-apply

function construct(Class, ...args) {
return new Class(...args);
}
7 changes: 7 additions & 0 deletions Task5/question4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// http://www.codewars.com/kata/santaclausable-interface

function isSantaClausable(obj) {
if (typeof(obj.sayHoHoHo) == "function" && typeof(obj.distributeGifts) == "function" && typeof(obj.goDownTheChimney) == "function")
return true;
return false;
}