Skip to content

Instantly share code, notes, and snippets.

Avatar

Chigozie Ekwonu chygoz2

View GitHub Profile
@chygoz2
chygoz2 / Program.cs
Created May 30, 2021
Algorithm week 8 challenge
View Program.cs
using System;
using System.Collections.Generic;
namespace NumberCombinations
{
class Program
{
static void Main(string[] args)
{
@chygoz2
chygoz2 / Program.cs
Last active May 28, 2021
Algorithm week 7 challenge
View Program.cs
using System;
using System.Linq;
namespace minimumDifference
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine(Program.getMinimumDifference(new string[] { "16:15", "16:00", "12:20" }));
@chygoz2
chygoz2 / shuffleClass.js
Last active May 16, 2021
Algorithm week 6 challenge
View shuffleClass.js
const shuffleClass = (classList, count) => {
if (isNaN(count) || !Array.isArray(classList)) throw new Error('Invalid input ');
let newClassList = [];
if (count === 0 || Math.abs(count) >= classList.length) return classList;
if (count > 0) {
for (let i = classList.length - count; i < classList.length; i++) {
newClassList.push(classList[i]);
@chygoz2
chygoz2 / mergeAges.ts
Last active May 13, 2021
Algorithm Fridays 5 solution
View mergeAges.ts
const mergeAges = (classA: Array<number>, classB: Array<number>) => {
let mergedAges: Array<number> = []
let i = 0, j = 0
while(i < classA.length && j < classB.length) {
if (isNaN(classA[i]) || isNaN(classB[j])) throw new Error('Invalid input')
if (classA[i] <= classB[j]) {
mergedAges.push(classA[i++])
@chygoz2
chygoz2 / arrayProduct.js
Last active May 2, 2021
Algorithm challenge week 4 solution
View arrayProduct.js
const arrayProduct = nums => {
if(!Array.isArray(nums)) throw new Error('Invalid input')
let product = 1
let countOfZeros = 0;
let productWithoutZeros = 1
for (let i = 0, j = nums.length - 1; i <= j; i++, j--) {
if (typeof nums[i] != 'number' || typeof nums[j] != 'number') throw new Error('Invalid input')
@chygoz2
chygoz2 / startAndEnd.js
Last active Apr 27, 2021
Algo friday 3 solution
View startAndEnd.js
const startAndEnd = (nums, val) => {
if (!Array.isArray(nums) || typeof val !== 'number') throw new Error('Invalid input')
const min = Math.min(...nums);
let positions = [-1, -1]
let countLessThanVal = 0
let countOfVal = 0
let countOfMin = 0
@chygoz2
chygoz2 / removeInstance.js
Last active Apr 24, 2021
Algo friday 2 solution
View removeInstance.js
function removeInstance(nums, val) {
if (!Array.isArray(nums)) throw new Error('Invalid input')
return nums.filter(entry => entry !== val).length
}
View Sock Merchant Solution in Java
static int sockMerchant(int n, int[] ar) {
Set set = new HashSet<Integer>();
int noOfPairs = 0;
for (int i=0; i<n; i++) {
if (set.contains(ar[i])) {
noOfPairs++;
set.remove(ar[i]);
} else {
set.add(ar[i]);
}
@chygoz2
chygoz2 / gist:efd264cd41baa4e820bbbb3e2d6e9895
Created Oct 18, 2018
Gist demonstrating the use of Promises and async/await to handle asynchronous operations in loops
View gist:efd264cd41baa4e820bbbb3e2d6e9895
import axios from 'axios'
const API_ENDPOINT = 'https://sample-flights-api.com/cities/'
async function getAirports (cityCodes) {
let promises = []
let airports = []
cityCodes.forEach(city => {
let promise = new Promise(async (resolve, reject) => {
try {
let { data } = await axios.get(`${API_ENDPOINT}city`)