Skip to content

Instantly share code, notes, and snippets.

View TechWithTy's full-sized avatar
🎯
Focusing

TechWIthTy TechWithTy

🎯
Focusing
View GitHub Profile
@TechWithTy
TechWithTy / removeDuplicates.js
Created October 30, 2020 21:49
Remove duplicates from array javscript
/**
* @param {number[]} nums
* @return {number}
*/
var removeDuplicates = function(nums) {
nums.forEach((num,i) => {
if(nums[i+1] !== null && nums[i+1] == nums[i] ){
nums.splice(i, 1);
console.log(nums)
removeDuplicates(nums)
@TechWithTy
TechWithTy / runningSum.js
Created October 30, 2020 20:17
Running sum O(n) Leetcode
/**
* @param {number[]} nums
* @return {number[]}
*/
var runningSum = function(nums) {
let newNums = [];
let numsSum = 0;
nums.forEach((num,i) =>{
if(nums[i] !== null){
@TechWithTy
TechWithTy / ValidParn.js
Created October 27, 2020 01:45
Valid Parenthesis LeetCode Algorithim
// /**
// * @param {string} s
// * @return {boolean}
// */
let brackets = {
"(": ")",
"[": "]",
"{": "}",
};
@TechWithTy
TechWithTy / mergeLinkedLists.js
Created October 27, 2020 00:55
Merge Two sorted Linked lists
let mergeTwoLists = function (l1, l2) {
let dummy = new ListNode(-1);
let head = dummy;
while (l1 !== null && l2 !== null) {
if (l1.val <= l2.val) {
dummy.next = l1;
l1 = l1.next;
} else {
dummy.next = l2;
@TechWithTy
TechWithTy / Longest Common Prefix LeetCode.js
Created October 20, 2020 01:49
Longest Common Prefix LeetCode
/** Initial Hypothesis
* @param {string[]} strs
* @return {string}
*/
var longestCommonPrefix = function(strs) {
let splitWords = [];
let commonPrefix =[];
strs.forEach((word,i) =>{
splitWords[i] = word.split('');
})
@TechWithTy
TechWithTy / Roman Numeral Problem
Created October 18, 2020 05:21
Solution to roman numeral problem
/**
* @param {string} s
* @return {number}
*/
var romanToInt = function(s) {
romanNumerals = {
I: 1,
V: 5,
X: 10,
L: 50,
@TechWithTy
TechWithTy / Palindrome Number in JavaScript
Created October 12, 2020 03:07
Find out if value is a palindrome
/**
* @param {number} x
* @return {boolean}
*/
var isPalindrome = function(x) {
let reversedNum = 0
//Passes
if(x < 0){
return false;
}else{
@TechWithTy
TechWithTy / Reverse Intiger Algorithim
Last active September 27, 2020 20:43
Reverse Intiger Algorithim
/**
* @param {number} x
* @return {number}
*/
var reverse = function (x) {
return parseFloat(x.toString().split('').reverse().join('')) * Math.sign(x);
};
//https://www.freecodecamp.org/news/js-basics-how-to-reverse-a-number-9aefc20afa8d/
@TechWithTy
TechWithTy / Two Sum.js
Created September 27, 2020 02:49
LeetCode Two Sum Problem
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
previousValues = {}; // Set Previous Hash Values
for (let i = 0; i < nums.length; i++){ // Loop through entire array
currentNum = nums[i]; // Get Current Loop Number
neededNum = target - currentNum; //Calculate Number Needed
@TechWithTy
TechWithTy / Linked List Tests
Created September 20, 2020 23:59
Linked List Tests with Jest
const LinkedList = require('./LinkedList')
describe('#insertAtHead', () => {
test('it adds the element to the beginning of the list', () => {
const ll = new LinkedList()
ll.insertAtHead(10)
const oldHead = ll.head
ll.insertAtHead(20)
expect(ll.head.value).toBe(20)