Skip to content

Instantly share code, notes, and snippets.

View nitecity's full-sized avatar

NiteCity nitecity

View GitHub Profile
@nitecity
nitecity / main.js
Last active September 23, 2022 00:36
Code Challenge: subLength('Saturday', 'a'); // returns 6
const absolute = (num1,num2) => {
if (num1 === num2) {
return num1 - num2;
} else if (num1 < num2) {
return num2 - num1;
} else {
return num1 - num2;
}
}
@nitecity
nitecity / main.js
Last active September 23, 2022 00:29
Output: 'Carrots, Hummus, Pesto and Rigatoni'
const groceries = (input) => {
let arr = [];
for(let i = 0; i < input.length; i++) {
if ( i === 0) {
arr.push(input[i]['item']);
} else {
arr.push(' ' + input[i]['item']);
}
if(i === input.length-1 && i !== 0) {
@nitecity
nitecity / main.js
Created September 21, 2022 02:51
Mysterious Organism
// Returns a random DNA base
const returnRandBase = () => {
const dnaBases = ['A', 'T', 'C', 'G'];
return dnaBases[Math.floor(Math.random() * 4)]
};
// Returns a random single stand of DNA containing 15 bases
const mockUpStrand = () => {
const newStrand = [];
for (let i = 0; i < 15; i++) {
@nitecity
nitecity / main.js
Created September 21, 2022 02:22
Credit Card Checker
// All valid credit card numbers
const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8];
const valid2 = [5, 5, 3, 5, 7, 6, 6, 7, 6, 8, 7, 5, 1, 4, 3, 9];
const valid3 = [3, 7, 1, 6, 1, 2, 0, 1, 9, 9, 8, 5, 2, 3, 6];
const valid4 = [6, 0, 1, 1, 1, 4, 4, 3, 4, 0, 6, 8, 2, 9, 0, 5];
const valid5 = [4, 5, 3, 9, 4, 0, 4, 9, 6, 7, 8, 6, 9, 6, 6, 6];
// All invalid credit card numbers
const invalid1 = [4, 5, 3, 2, 7, 7, 8, 7, 7, 1, 0, 9, 1, 7, 9, 5];
const invalid2 = [5, 7, 9, 5, 5, 9, 3, 3, 9, 2, 1, 3, 4, 6, 4, 3];
@nitecity
nitecity / library.js
Created September 21, 2022 02:14
Build a Library
class Media {
constructor(title){
this._title = title
this._ratings = []
this._isCheckedOut = false
}
get title(){return this._title}
get ratings(){return this._ratings}
get isCheckedOut(){return this._isCheckedOut}
set isCheckedOut(param){