Instantly share code, notes, and snippets.

🏠
Working from home

# Ayodeji Moronkeji d-beloved

🏠
Working from home
Last active Dec 21, 2020
View _Question.md

An array of integers is defined as being in meandering order when the first two elements are the respective largest and smallest elements in the array and the subsequent elements alternate between its next largest and next smallest elements. In other words, the elements are in order of [first_largest, first_smallest, second_largest, second_smallest, ...].

Example

The array [5, 2, 7, 8, -2, 25, 25] sorted normally is [-2, 2, 5, 7, 8, 25, 25]. Sorted in meandering order, it becomes [25, -2, 25, 2, 8, 5, 7]

Function Description

The function takes one parameter, unsorted[n]: the unsorted array

Created Jun 3, 2020
A function to check if a second array is a subsequence of the first one
View validateSubsequence.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 function isValidSubsequence(array, sequence) { /* On getting two non-empty integer arrays, for example [1, 4, 5, 2, 9, 13, 11] A second array [4, 2, 11] can be said to be a subsequence of the first one because it contains all the element present in the first one in the same order those appear in the first one, even though they are not adjacent. The algorithm below works by comparing the two array, looping through the first one once and then checking for each value if it is equal to the element in the subsequence array, once a match is found, it's on to the next element in the subsequence. Note that if no match is found, the lenght of the subsequence array will never be same as the value of variable "Seq"
Last active Oct 23, 2020
A simple Three Number Sum Algorithm implementation
View threeNumSumAlgo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 // using the pointer method the three number algorithm is solved let threeSumArray = (array, targetSum) => { array.sort((a, b) => a - b); const triplet = [] for (let i = 0; i < array.length - 2; i++) { // initialize the pointers let left = i + 1 let right = array.length - 1 while (left < right) { let currentSum = array[i] + array[left] + array[right]
Last active Apr 10, 2020
Two Number Sum algorithm (Solution using two methods)
View numSumAlgo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 // Two Number sum algorithm challenge // Solution using the algebraic method const twoNumberSum = (array, targetSum) => { const hashTable = {} for (let value of array) { let yValue = targetSum - value; if (hashTable[yValue]) { return [yValue, value] } else {