Skip to content

Instantly share code, notes, and snippets.

@tbanj
Created April 25, 2019 08:36
Show Gist options
  • Save tbanj/7a13e4f93016d398c1f8e2e8010c856f to your computer and use it in GitHub Desktop.
Save tbanj/7a13e4f93016d398c1f8e2e8010c856f to your computer and use it in GitHub Desktop.
This gist entails using javascript to implement array multiplier, email generator from firstname & lastname which are the parameters which the input will make use of, calling cat api which return facts about api
// This gist entail using javascript to implement array multiplier
var arrayMulti = [5, 10, 7, 11];
const arrayMap = arrayMulti.map((element) => {return element * 2;});
console.log(arrayMap);
// This is an integration test to test return of http request of https://cat-fact.herokuapp.com/facts/random
const expect = require('chai').expect;
const catFact = require('../server');
describe('Test for Cat Facts API', () => {
it('expect res type to equal object', () => {
return catFact.methodCat().then(res => {
expect(typeof res).to.equal('object');
})
});
});
// This is an email generator function which accepts two parameters..firstname & lastname which he make use to form an email
function emailGenerator(firstname, lastname) {
if ((typeof firstname === 'string') && firstname.length > 0 && lastname.length > 0 && (typeof lastname === 'string') ) {
const email = `${firstname}_${lastname}@yahoo.com`;
return email;
} else{
return 'invalid paramters inputted'
}
}
console.log(emailGenerator("alabi","wahab"));
// below function is use to make http request to the https://cat-fact.herokuapp.com/#/ api and returns random facts about cats
// once fact about cat everyday
const axios = require('axios');
module.exports = {
methodCat: checkCat
}
async function checkCat() {
let result;
try {
result = await axios({
method:'get',
url:`https://cat-fact.herokuapp.com/facts/random`
});
} catch (error) {
console.error(error);
}
return result.data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment