Skip to content

Instantly share code, notes, and snippets.

View alex-hladun's full-sized avatar
🏠
Working from home

Alex Hladun alex-hladun

🏠
Working from home
  • Accolite Digital
  • Calgary
View GitHub Profile
@alex-hladun
alex-hladun / pigLatin.js
Created May 25, 2020 23:06
Creates a pig latin representation of a string using node command-line arguments.
const args = process.argv.slice(2);
let str = "";
for (let i = 0; i <= args.length - 1; i++) {
let phrase = "";
let firstLetter = "";
for (let j = 0; j <= args[i].length - 1; j++) {
if (j === 0) {
firstLetter = args[i][0];
} else {
@alex-hladun
alex-hladun / palindromeChecker.js
Created May 26, 2020 21:13
Checks whether a string is a palindrome or not.
// FUNCTION IMPLEMENTATION (MULTIPLE BUGS)
const isPalindrome = function(str) {
const noSpaces = str.split(" ").join("");
console.log(noSpaces);
const midIndex = Math.floor(noSpaces.length/2);
const lastIndex = noSpaces.length - 1;
for (let i = 0; i < midIndex; i++) {
// console.log(str[i])
// console.log(str[lastIndex - i])
@alex-hladun
alex-hladun / joinList
Created May 26, 2020 22:51
Joins a string of characters together in a string.
/*
* Write a function that joins the contents of conceptList together
* into one String, concepts, with each list item separated from
* the previous by a comma.
*
* To implement this we'll create a joinList function which will take
* in any array of strings return a comma-separated string.
*/
let joinList = function(list) {
@alex-hladun
alex-hladun / sales.js
Created May 27, 2020 03:48
Calculates total sales and sales tax for company's sales across different provinces.
const calculateSalesTax = function(salesData, taxRates) {
const results = {};
// Iterate through each company in the list
for (let i = 0; i <= salesData.length - 1; i++) {
// Initialize results object if it doesn't exist.
if (!results[salesData[i]['name']]) {
results[salesData[i]['name']] = { totalSales: 0, totalTaxes: 0 };
@alex-hladun
alex-hladun / social.js
Created May 27, 2020 23:06
Given an object of social media metrics, returns certain stats.
const biggestFollower = function (data) {
let bigFollow = { name: "", followCount: 0 }
for (let id in data) {
if (data[id]['follows'].length > bigFollow.followCount) {
bigFollow.name = data[id]['name'];
bigFollow.followCount = data[id]['follows'].length;
}
}
console.log(`${bigFollow.name} follows the most people (${bigFollow.followCount}).`);
@alex-hladun
alex-hladun / advancedSortFunction.js
Created May 28, 2020 20:00
Sort through an array of objects using a specified sort function.
const students = [
{ id: 1, name: "bruce", age: 40 },
{ id: 2, name: "zoidberg", age: 22 },
{ id: 3, name: "alex", age: 22 },
{ id: 4, name: "alex", age: 30 }
];
const students2 = [
{ id: 1, name: "Frank", age: 100 },
{ id: 2, name: "Jay", age: 22 },
{ id: 3, name: "Frank", age: 22 },
@alex-hladun
alex-hladun / library.js
Last active May 29, 2020 01:56 — forked from kvirani/library.js
Music Library Exercise
const library = {
tracks: { t01: { id: "t01",
name: "Code Monkey",
artist: "Jonathan Coulton",
album: "Thing a Week Three" },
t02: { id: "t02",
name: "Model View Controller",
artist: "James Dempsey",
album: "WWDC 2003"},
t03: { id: "t03",
@alex-hladun
alex-hladun / recursionSum.js
Created May 29, 2020 17:43
Sum from one number to another recursively.
const sum = function(fromN, toN) {
if (fromN === toN) {
return toN;
} else {
return fromN + sum(fromN + 1, toN);
}
};
module.exports = sum;
@alex-hladun
alex-hladun / vampire.js
Last active June 11, 2020 16:52
Uses tree data structure and methods to determine required information. Also uses recursion for tree traversal.
class Vampire {
constructor(name, yearConverted) {
this.name = name;
this.yearConverted = yearConverted;
this.offspring = [];
this.creator = null;
}
/** Simple tree methods **/
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
</style>
</head>