Skip to content

Instantly share code, notes, and snippets.

@tobi-bams
tobi-bams / removeduplicate.js
Created April 10, 2021 09:54
A Function that removes duplicate values from a sorted Array
const removeDuplicates = (sortedArray) => {
const filteredArray = [];
sortedArray.forEach((num)=> {
if(!filteredArray.includes(num)) {
filteredArray.push(num);
}
});
return filteredArray.length;
}
const removeInstance = (nums, val) => {
if(!Array.isArray(nums) || nums.length === 0) return 0;
if(!val) return nums.length;
let newArrayLength = 0;
for(let i = 0; i < nums.length; i++) {
if(nums[i] !== val) {
const startAndStopPosition = (nums, val) => {
if(!Array.isArray(nums) || nums.length === 0) return [-1, -1];
// Initialization of Variables
let initialIndex = 0;
let count = 0;
let startAndStop = [];
// Looping through the array;
for(let i = 0; i < nums.length; i++) {
const productFunction = (nums) => {
let zeroCount = 0;
let temporalProduct = 1;
if(!Array.isArray(nums) || nums.length === 0) return [];
if(nums.length === 1) return [0];
const totalProduct = nums.reduce((product, num) => {
const sortFunction = (firstArray, secondArray) => {
if (
(!Array.isArray(firstArray) || firstArray.length === 0) &&
(!Array.isArray(secondArray) || secondArray.length === 0)
) {
return [];
}
if (!Array.isArray(firstArray) || firstArray.length === 0) {
return secondArray;
}
const shuffleClass = (arr, num) => {
if (!Array.isArray(arr) || arr.length === 0) return [];
if (typeof num !== "number") {
return arr;
}
if (num === 0) {
return arr;
}
const twoSum = (array, sum) => {
if (!Array.isArray(array) || array.length === 0) return [0, 0];
if (typeof sum !== "number") return [0, 0];
const secondValues = {};
for (let i = 0; i < array.length; i++) {
let secondValue = sum - array[i];
if (secondValues[array[i]]) {
const evenAndOdd = (array) => {
if (!Array.isArray(array) || array.length === 0) return [0, 0];
let evenSum = 0;
let oddSum = 0;
for(let i = 0; i < array.length; i++){
if(array[i] % 2 === 0) {
evenSum = evenSum + array[i];
}
else {
oddSum = oddSum + array[i];
const reverseVowels = (word) => {
if (typeof word !== 'string') return "Invalid Input Parameter";
let start = 0;
let end = word.length - 1;
let vowels = {
a: true,
e: true,
i: true,
o: true,
u: true,
@tobi-bams
tobi-bams / package.json
Created April 19, 2022 06:48
Package.json sample for the psbt article
{
"name": "psbt",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"keywords": [],
"author": "",