Skip to content

Instantly share code, notes, and snippets.

View neuralline's full-sized avatar

Darik. neuralline

View GitHub Profile
@neuralline
neuralline / maximumCharacter.js
Created December 24, 2020 03:09
Return maximum occurring character in an input string with functional JavaScript
/**
* Javascript Algorithms.
* Functional javascript using pure, recursive, compositing and ....
* @Licence Don't use this code for anything ever! :) but if you do, give credit where credit is due, MIT.
* @author Darik.
* @GitHub neuralline
*
*/
/**
@neuralline
neuralline / fibonacci-javascript-algorithm.js
Created December 21, 2020 18:19
Fibonacci recursive function using arrays and destructuring
/**
* Javascript Algorithms.
* Fibonacci function using arrays and recursive methods.
* Licence: Don't use this code for anything ever! :)
* But if you do, give credit where credit is due.
* @author Darik.
* @GitHub @neuralline
*
*
*
@neuralline
neuralline / request-multiple-urls.ts
Created December 21, 2020 03:14
Promise all fetch array of urls using async/await
const axios = require('axios')
//using axios because node does not support fetch out of the box
const requestMultipleUrls = async urls => {
try {
const response = await Promise.all(
urls.map(async url => {
const res = await await axios(url)
return res.data
})
@neuralline
neuralline / divide-array-into-n-equal-size.js
Last active December 20, 2020 00:12
ES6 break array Into n equal size
/**
*
* Given an array of length >= 0, and a positive integer N, return the contents of the array divided into N equally sized arrays.
* Where the size of the original array cannot be divided equally by N, the final part should have a length equal to the remainder.
*
* #my solution
* it's modern, its pure function, uses ES6 method channing and also it returns brand new array with out modifying the original
*
* @param {[]} arr original array
* @param {number} divideBy number
@neuralline
neuralline / method-chaining.js
Created May 1, 2020 15:43
ES6 Filter, Sort, Map method chaining
/* PRINT OUT TO THE CONSOLE,
AN ORDERED LIST OF "ACTIVE" USERS,
BY ASENDING SURNAME (ie A, B, C),
WITH A STRING SHOWING USERS FULL NAME AND AGE TO WHOLE NUMBER
ie
"Jerry Brie is 80 years old."
"Mickey Jacobs is 92 years old."
"Tom Oswalt is 80 years old."
*/
@neuralline
neuralline / async-await-for-loop.ts
Created April 19, 2020 11:51
async await for loop
//async for loop
//Why ? performance also browser support
const getGitHubUser = async (usernames: []) => {
//const results:[]:=[] //<-results array here
const length = usernames.length
for (let i = 0; i < length; i++) {
try {
const response = await fetch(
`https://api.github.com/users/${usernames[i]}`
@neuralline
neuralline / promise-allSettled-async-loop.ts
Created April 19, 2020 11:26
Promise.allSettled async await loop with map
//Promise.allSettled() vs Promise.all()
//allSettled: returns when all promises have either resolved or rejected
const getGitHubUser = async (usernames: []) => {
const result = await Promise.allSettled(
usernames.map(async (name: string) => {
try {
const response = await fetch(
`https://api.github.com/users/${name}`
)
/** @format */
//@ts-check
/**
Vodafone coding challenge
You have been tasked with creating a helper function that will be used to determine the output
of an array of data.