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
/** | |
* 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 | |
* | |
*/ | |
/** |
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
/** | |
* 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 | |
* | |
* | |
* |
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
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 | |
}) |
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
/** | |
* | |
* 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 |
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
/* 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." | |
*/ |
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
//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]}` |
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
//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}` | |
) |
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
/** @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. |