Skip to content

Instantly share code, notes, and snippets.

View TheSaviourEking's full-sized avatar
:octocat:
Coding a feature!

Saviour Eking TheSaviourEking

:octocat:
Coding a feature!
View GitHub Profile
@TheSaviourEking
TheSaviourEking / guessing-game.js
Last active September 4, 2023 03:48
Number Guessing Game A simple number guessing game implemented in JavaScript. The game prompts the user to specify the range of numbers and the number of attempts they want to make. Then, it generates a random number within the specified range, and the user tries to guess the secret number within the given number of attempts. The game provides f…
// Require the 'readline' module to handle user input.
readline = require('node:readline');
/**
* Create an interface for reading user input from the console.
* @type {readline.Interface}
*/
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout // Use process.stdout for output
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Tags Cheat Sheet</title>
</head>
<body>
<h1 id="top-of-page">My HTML Cheat Sheet</h1>
@TheSaviourEking
TheSaviourEking / index.js
Created September 27, 2023 23:24
A file to test my understanding of Space and Time Complexities
animals = [
'alligator', 'bear', 'cat', 'dog', 'elephant',
'fish', 'goose', 'hamster', 'iguana', 'jaguar', 'kangaroo'
];
// Count how many animals are in the list
// Time complexity: O(?) // O(n)
// Space complexity: O(?) // o(1)
function countAnimals(animals) {
let count = 0;
/* Identify the time complexity of each of these functions with a 1 sentence justification for your answer. Assume arr is an array of length n.
arr.push()
Time complexity: O(1) Space complexity: O(1) Justification: .push() mutates the input array inplace there by not using the array's length property to identify a valid length and placing the new element at that position, it also does'nt create an new array
push on MDN
arr.pop()
Time complexity: O(1) Space complexity: O(1) Justification: .pop() works just like push()

Binary Practice

Binary to base 10

  1. ob1010 => 10
  2. ob0011 => 3

Binary to hexadecimal

  1. ob1010 => 0x10
  2. ob0011 => 0x3
@TheSaviourEking
TheSaviourEking / hashTable.js
Last active October 26, 2023 04:34
still working on making my hashMap faster to pass the timing test for constant time lookup even when there's collisions
class KeyValuePair {
constructor(key, value) {
this.key = key;
this.value = value;
this.next = null;
}
}
class HashTable { // get O(1), set O(1), deleteKey O(1)