Skip to content

Instantly share code, notes, and snippets.

@udnisap
Created November 21, 2018 05:18
Show Gist options
  • Save udnisap/5c395ca404ea086687cc1a12b748cd64 to your computer and use it in GitHub Desktop.
Save udnisap/5c395ca404ea086687cc1a12b748cd64 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/faqanut
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script>
let data = [1,10,4,5,3,5,1,4,5];
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/jasmine.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/jasmine-html.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/boot.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/jasmine.min.css"/>
<script>
console.clear();
// console.log('Lodash version', _.VERSION);
console.log('Jasmin version', jasmine.version);
jasmine.currentEnv_.configure({random: false, hideDisabled : true})
const clockSpeed = 100;
const wait = () => {
const millis = clockSpeed;
const date = new Date();
let curDate = null;
do { curDate = new Date(); }
while(curDate-date < millis);
}
const isEven = num => {
wait();
return num % 2 === 0;
}
</script>
<script>
const countries = [
{
"name": "Andorra",
"currency": "EUR",
"code": "AD",
"continent": {
"code": "EU",
"name": "Europe"
},
"languages": [
{
"name": "Catalan",
"code": "ca"
}
]
},
{
"name": "United Arab Emirates",
"currency": "AED",
"code": "AE",
"continent": {
"code": "AS",
"name": "Asia"
},
"languages": [
{
"name": "Arabic",
"code": "ar"
}
]
},
{
"name": "Afghanistan",
"currency": "AFN",
"code": "AF",
"continent": {
"code": "AS",
"name": "Asia"
},
"languages": [
{
"name": "Pashto",
"code": "ps"
},
{
"name": "Turkmen",
"code": "tk"
},
{
"name": "Uzbek",
"code": "uz"
}
]
},
{
"name": "Antigua and Barbuda",
"currency": "XCD",
"code": "AG",
"continent": {
"code": "NA",
"name": "North America"
},
"languages": [
{
"name": "English",
"code": "en"
}
]
},
{
"name": "Anguilla",
"currency": "XCD",
"code": "AI",
"continent": {
"code": "NA",
"name": "North America"
},
"languages": [
{
"name": "English",
"code": "en"
}
]
},
{
"name": "Albania",
"currency": "ALL",
"code": "AL",
"continent": {
"code": "EU",
"name": "Europe"
},
"languages": [
{
"name": "Albanian",
"code": "sq"
}
]
},
{
"name": "Armenia",
"currency": "AMD",
"code": "AM",
"continent": {
"code": "AS",
"name": "Asia"
},
"languages": [
{
"name": "Armenian",
"code": "hy"
},
{
"name": "Russian",
"code": "ru"
}
]
},
{
"name": "Angola",
"currency": "AOA",
"code": "AO",
"continent": {
"code": "AF",
"name": "Africa"
},
"languages": [
{
"name": "Portuguese",
"code": "pt"
}
]
},
{
"name": "Antarctica",
"currency": "",
"code": "AQ",
"continent": {
"code": "AN",
"name": "Antarctica"
},
"languages": []
},
{
"name": "Argentina",
"currency": "ARS",
"code": "AR",
"continent": {
"code": "SA",
"name": "South America"
},
"languages": [
{
"name": "Spanish",
"code": "es"
},
{
"name": "Guarani",
"code": "gn"
}
]
},
{
"name": "American Samoa",
"currency": "USD",
"code": "AS",
"continent": {
"code": "OC",
"name": "Oceania"
},
"languages": [
{
"name": "English",
"code": "en"
},
{
"name": "Samoan",
"code": "sm"
}
]
},
{
"name": "Austria",
"currency": "EUR",
"code": "AT",
"continent": {
"code": "EU",
"name": "Europe"
},
"languages": [
{
"name": "German",
"code": "de"
}
]
},
{
"name": "Australia",
"currency": "AUD",
"code": "AU",
"continent": {
"code": "OC",
"name": "Oceania"
},
"languages": [
{
"name": "English",
"code": "en"
}
]
},
{
"name": "Aruba",
"currency": "AWG",
"code": "AW",
"continent": {
"code": "NA",
"name": "North America"
},
"languages": [
{
"name": "Dutch",
"code": "nl"
},
{
"name": "Panjabi / Punjabi",
"code": "pa"
}
]
},
{
"name": "Åland",
"currency": "EUR",
"code": "AX",
"continent": {
"code": "EU",
"name": "Europe"
},
"languages": [
{
"name": "Swedish",
"code": "sv"
}
]
},
{
"name": "Azerbaijan",
"currency": "AZN",
"code": "AZ",
"continent": {
"code": "AS",
"name": "Asia"
},
"languages": [
{
"name": "Azerbaijani",
"code": "az"
}
]
},
{
"name": "Bosnia and Herzegovina",
"currency": "BAM",
"code": "BA",
"continent": {
"code": "EU",
"name": "Europe"
},
"languages": [
{
"name": "Bosnian",
"code": "bs"
},
{
"name": "Croatian",
"code": "hr"
},
{
"name": "Serbian",
"code": "sr"
}
]
},
{
"name": "Barbados",
"currency": "BBD",
"code": "BB",
"continent": {
"code": "NA",
"name": "North America"
},
"languages": [
{
"name": "English",
"code": "en"
}
]
},
{
"name": "Bangladesh",
"currency": "BDT",
"code": "BD",
"continent": {
"code": "AS",
"name": "Asia"
},
"languages": [
{
"name": "Bengali",
"code": "bn"
}
]
},
{
"name": "Belgium",
"currency": "EUR",
"code": "BE",
"continent": {
"code": "EU",
"name": "Europe"
},
"languages": [
{
"name": "German",
"code": "de"
},
{
"name": "French",
"code": "fr"
},
{
"name": "Dutch",
"code": "nl"
}
]
},
{
"name": "Burkina Faso",
"currency": "XOF",
"code": "BF",
"continent": {
"code": "AF",
"name": "Africa"
},
"languages": [
{
"name": "Peul",
"code": "ff"
},
{
"name": "French",
"code": "fr"
}
]
},
{
"name": "Bulgaria",
"currency": "BGN",
"code": "BG",
"continent": {
"code": "EU",
"name": "Europe"
},
"languages": [
{
"name": "Bulgarian",
"code": "bg"
}
]
},
{
"name": "Bahrain",
"currency": "BHD",
"code": "BH",
"continent": {
"code": "AS",
"name": "Asia"
},
"languages": [
{
"name": "Arabic",
"code": "ar"
}
]
},
{
"name": "Burundi",
"currency": "BIF",
"code": "BI",
"continent": {
"code": "AF",
"name": "Africa"
},
"languages": [
{
"name": "French",
"code": "fr"
},
{
"name": "Kirundi",
"code": "rn"
}
]
},
{
"name": "Benin",
"currency": "XOF",
"code": "BJ",
"continent": {
"code": "AF",
"name": "Africa"
},
"languages": [
{
"name": "French",
"code": "fr"
}
]
},
{
"name": "Saint Barthélemy",
"currency": "EUR",
"code": "BL",
"continent": {
"code": "NA",
"name": "North America"
},
"languages": [
{
"name": "French",
"code": "fr"
}
]
},
{
"name": "Bermuda",
"currency": "BMD",
"code": "BM",
"continent": {
"code": "NA",
"name": "North America"
},
"languages": [
{
"name": "English",
"code": "en"
}
]
},
{
"name": "Brunei",
"currency": "BND",
"code": "BN",
"continent": {
"code": "AS",
"name": "Asia"
},
"languages": [
{
"name": "Malay",
"code": "ms"
}
]
},
{
"name": "Bolivia",
"currency": "BOB,BOV",
"code": "BO",
"continent": {
"code": "SA",
"name": "South America"
},
"languages": [
{
"name": "Aymara",
"code": "ay"
},
{
"name": "Spanish",
"code": "es"
},
{
"name": "Quechua",
"code": "qu"
}
]
},
{
"name": "Bonaire",
"currency": "USD",
"code": "BQ",
"continent": {
"code": "NA",
"name": "North America"
},
"languages": [
{
"name": "Dutch",
"code": "nl"
}
]
}
];
</script>
<script src="https://cdn.jsdelivr.net/g/lodash@4(lodash.js+lodash.fp.js)"></script>
</script>
</head>
<body>
<script id="jsbin-javascript">
// noprotect
// Write your code here
// TESTS
describe('Loops vs Iteration', () => {
describe('isEven', () => {
it('1 is not even', () => {
expect(isEven(1)).toEqual(false);
});
it('2 is even', () => {
expect(isEven(2)).toEqual(true);
});
it('12 is even', () => {
expect(isEven(12)).toEqual(true);
});
it('should be slower', () => {
const startTime = +new Date();
const predicate = isEven(5);
const seconds = +new Date() - startTime;
expect(seconds).toBeGreaterThanOrEqual(clockSpeed);
});
});
xdescribe('getFirstEvens', () => {
it('should return empty list if empty', () => {
expect(getFirstEvens([], 1)).toEqual([]);
});
it('should return empty list if only odds', () => {
expect(getFirstEvens([1, 5], 2)).toEqual([]);
});
it('should return the first n evens', () => {
expect(getFirstEvens([1, 2, 4, 7, 8], 2)).toEqual([2, 4]);
});
it('should only check upto required n', () => {
const startTime = +new Date();
const firstEvens = getFirstEvens([2, 4, 6, 20, 4, 22], 2);
const seconds = +new Date() - startTime;
expect(firstEvens).toEqual([2, 4]);
expect(seconds).toBeLessThan(clockSpeed * 3);
});
})
});
xdescribe('Map / Filter / Reduce', () => {
xdescribe('Map with arrayMul2', () => {
it('should return empty list if no numbers', () => {
expect(arrayMul2([])).toEqual([]);
});
it('should return multiplied numbers', () => {
expect(arrayMul2([1, 2, 3])).toEqual([2, 4, 6]);
});
});
xdescribe('Filter with arrayEvens', () => {
it('should return empty list if no numbers', () => {
expect(arrayEvens([])).toEqual([]);
});
it('should return even numbers', () => {
expect(arrayEvens([1,3,5,62,4])).toEqual([62,4]);
});
});
xdescribe('Reduce with arraySum', () => {
it('should return zero if no numbers', () => {
expect(arraySum([])).toEqual(0);
});
it('should return sum when specified', () => {
expect(arraySum([1,2,3])).toEqual(6);
});
});
xdescribe('Reduce with arrayMul', () => {
it('should return one if empty', () => {
expect(arrayMul([])).toEqual(1);
});
it('should return product when specified', () => {
expect(arrayMul([1,2,3])).toEqual(6);
});
});
})
xdescribe('Curry', () => {
describe('arrayMul2', () => {
it('should return empty list if no numbers', () => {
expect(arrayMul2([])).toEqual([]);
});
it('should return multiplied numbers', () => {
expect(arrayMul2([1, 2, 3])).toEqual([2, 4, 6]);
});
});
describe('arrayMul3', () => {
it('should return empty list if no numbers', () => {
expect(arrayMul3([])).toEqual([]);
});
it('should return multiplied numbers', () => {
expect(arrayMul3([1, 2, 3])).toEqual([3, 6, 9]);
});
});
});
xdescribe('FlatMap', () => {
describe('getLanguages', ()=> {
it('should return uniq languages', () => {
const cs = getLanguages(countries);
expect(cs.length).toEqual(29);
})
})
});
xdescribe('GroupBy', () => {
describe('getCountryByLanguages', ()=> {
it('should return country by language', () => {
const cs = getCountryByLanguages(countries);
console.log(cs)
expect(Object.keys(cs).length).toEqual(29);
})
})
})
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script>
let data = [1,10,4,5,3,5,1,4,5];
<\/script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/jasmine.js"><\/script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/jasmine-html.js"><\/script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/boot.js"><\/script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/jasmine.min.css"/>
<script>
console.clear();
// console.log('Lodash version', _.VERSION);
console.log('Jasmin version', jasmine.version);
jasmine.currentEnv_.configure({random: false, hideDisabled : true})
const clockSpeed = 100;
const wait = () => {
const millis = clockSpeed;
const date = new Date();
let curDate = null;
do { curDate = new Date(); }
while(curDate-date < millis);
}
const isEven = num => {
wait();
return num % 2 === 0;
}
<\/script>
<script>
const countries = [
{
"name": "Andorra",
"currency": "EUR",
"code": "AD",
"continent": {
"code": "EU",
"name": "Europe"
},
"languages": [
{
"name": "Catalan",
"code": "ca"
}
]
},
{
"name": "United Arab Emirates",
"currency": "AED",
"code": "AE",
"continent": {
"code": "AS",
"name": "Asia"
},
"languages": [
{
"name": "Arabic",
"code": "ar"
}
]
},
{
"name": "Afghanistan",
"currency": "AFN",
"code": "AF",
"continent": {
"code": "AS",
"name": "Asia"
},
"languages": [
{
"name": "Pashto",
"code": "ps"
},
{
"name": "Turkmen",
"code": "tk"
},
{
"name": "Uzbek",
"code": "uz"
}
]
},
{
"name": "Antigua and Barbuda",
"currency": "XCD",
"code": "AG",
"continent": {
"code": "NA",
"name": "North America"
},
"languages": [
{
"name": "English",
"code": "en"
}
]
},
{
"name": "Anguilla",
"currency": "XCD",
"code": "AI",
"continent": {
"code": "NA",
"name": "North America"
},
"languages": [
{
"name": "English",
"code": "en"
}
]
},
{
"name": "Albania",
"currency": "ALL",
"code": "AL",
"continent": {
"code": "EU",
"name": "Europe"
},
"languages": [
{
"name": "Albanian",
"code": "sq"
}
]
},
{
"name": "Armenia",
"currency": "AMD",
"code": "AM",
"continent": {
"code": "AS",
"name": "Asia"
},
"languages": [
{
"name": "Armenian",
"code": "hy"
},
{
"name": "Russian",
"code": "ru"
}
]
},
{
"name": "Angola",
"currency": "AOA",
"code": "AO",
"continent": {
"code": "AF",
"name": "Africa"
},
"languages": [
{
"name": "Portuguese",
"code": "pt"
}
]
},
{
"name": "Antarctica",
"currency": "",
"code": "AQ",
"continent": {
"code": "AN",
"name": "Antarctica"
},
"languages": []
},
{
"name": "Argentina",
"currency": "ARS",
"code": "AR",
"continent": {
"code": "SA",
"name": "South America"
},
"languages": [
{
"name": "Spanish",
"code": "es"
},
{
"name": "Guarani",
"code": "gn"
}
]
},
{
"name": "American Samoa",
"currency": "USD",
"code": "AS",
"continent": {
"code": "OC",
"name": "Oceania"
},
"languages": [
{
"name": "English",
"code": "en"
},
{
"name": "Samoan",
"code": "sm"
}
]
},
{
"name": "Austria",
"currency": "EUR",
"code": "AT",
"continent": {
"code": "EU",
"name": "Europe"
},
"languages": [
{
"name": "German",
"code": "de"
}
]
},
{
"name": "Australia",
"currency": "AUD",
"code": "AU",
"continent": {
"code": "OC",
"name": "Oceania"
},
"languages": [
{
"name": "English",
"code": "en"
}
]
},
{
"name": "Aruba",
"currency": "AWG",
"code": "AW",
"continent": {
"code": "NA",
"name": "North America"
},
"languages": [
{
"name": "Dutch",
"code": "nl"
},
{
"name": "Panjabi / Punjabi",
"code": "pa"
}
]
},
{
"name": "Åland",
"currency": "EUR",
"code": "AX",
"continent": {
"code": "EU",
"name": "Europe"
},
"languages": [
{
"name": "Swedish",
"code": "sv"
}
]
},
{
"name": "Azerbaijan",
"currency": "AZN",
"code": "AZ",
"continent": {
"code": "AS",
"name": "Asia"
},
"languages": [
{
"name": "Azerbaijani",
"code": "az"
}
]
},
{
"name": "Bosnia and Herzegovina",
"currency": "BAM",
"code": "BA",
"continent": {
"code": "EU",
"name": "Europe"
},
"languages": [
{
"name": "Bosnian",
"code": "bs"
},
{
"name": "Croatian",
"code": "hr"
},
{
"name": "Serbian",
"code": "sr"
}
]
},
{
"name": "Barbados",
"currency": "BBD",
"code": "BB",
"continent": {
"code": "NA",
"name": "North America"
},
"languages": [
{
"name": "English",
"code": "en"
}
]
},
{
"name": "Bangladesh",
"currency": "BDT",
"code": "BD",
"continent": {
"code": "AS",
"name": "Asia"
},
"languages": [
{
"name": "Bengali",
"code": "bn"
}
]
},
{
"name": "Belgium",
"currency": "EUR",
"code": "BE",
"continent": {
"code": "EU",
"name": "Europe"
},
"languages": [
{
"name": "German",
"code": "de"
},
{
"name": "French",
"code": "fr"
},
{
"name": "Dutch",
"code": "nl"
}
]
},
{
"name": "Burkina Faso",
"currency": "XOF",
"code": "BF",
"continent": {
"code": "AF",
"name": "Africa"
},
"languages": [
{
"name": "Peul",
"code": "ff"
},
{
"name": "French",
"code": "fr"
}
]
},
{
"name": "Bulgaria",
"currency": "BGN",
"code": "BG",
"continent": {
"code": "EU",
"name": "Europe"
},
"languages": [
{
"name": "Bulgarian",
"code": "bg"
}
]
},
{
"name": "Bahrain",
"currency": "BHD",
"code": "BH",
"continent": {
"code": "AS",
"name": "Asia"
},
"languages": [
{
"name": "Arabic",
"code": "ar"
}
]
},
{
"name": "Burundi",
"currency": "BIF",
"code": "BI",
"continent": {
"code": "AF",
"name": "Africa"
},
"languages": [
{
"name": "French",
"code": "fr"
},
{
"name": "Kirundi",
"code": "rn"
}
]
},
{
"name": "Benin",
"currency": "XOF",
"code": "BJ",
"continent": {
"code": "AF",
"name": "Africa"
},
"languages": [
{
"name": "French",
"code": "fr"
}
]
},
{
"name": "Saint Barthélemy",
"currency": "EUR",
"code": "BL",
"continent": {
"code": "NA",
"name": "North America"
},
"languages": [
{
"name": "French",
"code": "fr"
}
]
},
{
"name": "Bermuda",
"currency": "BMD",
"code": "BM",
"continent": {
"code": "NA",
"name": "North America"
},
"languages": [
{
"name": "English",
"code": "en"
}
]
},
{
"name": "Brunei",
"currency": "BND",
"code": "BN",
"continent": {
"code": "AS",
"name": "Asia"
},
"languages": [
{
"name": "Malay",
"code": "ms"
}
]
},
{
"name": "Bolivia",
"currency": "BOB,BOV",
"code": "BO",
"continent": {
"code": "SA",
"name": "South America"
},
"languages": [
{
"name": "Aymara",
"code": "ay"
},
{
"name": "Spanish",
"code": "es"
},
{
"name": "Quechua",
"code": "qu"
}
]
},
{
"name": "Bonaire",
"currency": "USD",
"code": "BQ",
"continent": {
"code": "NA",
"name": "North America"
},
"languages": [
{
"name": "Dutch",
"code": "nl"
}
]
}
];
<\/script>
<script src="https://cdn.jsdelivr.net/g/lodash@4(lodash.js+lodash.fp.js)"><\/script>
<\/script>
</head>
<body>
</body>
</html>
</script>
<script id="jsbin-source-javascript" type="text/javascript">// noprotect
// Write your code here
// TESTS
describe('Loops vs Iteration', () => {
describe('isEven', () => {
it('1 is not even', () => {
expect(isEven(1)).toEqual(false);
});
it('2 is even', () => {
expect(isEven(2)).toEqual(true);
});
it('12 is even', () => {
expect(isEven(12)).toEqual(true);
});
it('should be slower', () => {
const startTime = +new Date();
const predicate = isEven(5);
const seconds = +new Date() - startTime;
expect(seconds).toBeGreaterThanOrEqual(clockSpeed);
});
});
xdescribe('getFirstEvens', () => {
it('should return empty list if empty', () => {
expect(getFirstEvens([], 1)).toEqual([]);
});
it('should return empty list if only odds', () => {
expect(getFirstEvens([1, 5], 2)).toEqual([]);
});
it('should return the first n evens', () => {
expect(getFirstEvens([1, 2, 4, 7, 8], 2)).toEqual([2, 4]);
});
it('should only check upto required n', () => {
const startTime = +new Date();
const firstEvens = getFirstEvens([2, 4, 6, 20, 4, 22], 2);
const seconds = +new Date() - startTime;
expect(firstEvens).toEqual([2, 4]);
expect(seconds).toBeLessThan(clockSpeed * 3);
});
})
});
xdescribe('Map / Filter / Reduce', () => {
xdescribe('Map with arrayMul2', () => {
it('should return empty list if no numbers', () => {
expect(arrayMul2([])).toEqual([]);
});
it('should return multiplied numbers', () => {
expect(arrayMul2([1, 2, 3])).toEqual([2, 4, 6]);
});
});
xdescribe('Filter with arrayEvens', () => {
it('should return empty list if no numbers', () => {
expect(arrayEvens([])).toEqual([]);
});
it('should return even numbers', () => {
expect(arrayEvens([1,3,5,62,4])).toEqual([62,4]);
});
});
xdescribe('Reduce with arraySum', () => {
it('should return zero if no numbers', () => {
expect(arraySum([])).toEqual(0);
});
it('should return sum when specified', () => {
expect(arraySum([1,2,3])).toEqual(6);
});
});
xdescribe('Reduce with arrayMul', () => {
it('should return one if empty', () => {
expect(arrayMul([])).toEqual(1);
});
it('should return product when specified', () => {
expect(arrayMul([1,2,3])).toEqual(6);
});
});
})
xdescribe('Curry', () => {
describe('arrayMul2', () => {
it('should return empty list if no numbers', () => {
expect(arrayMul2([])).toEqual([]);
});
it('should return multiplied numbers', () => {
expect(arrayMul2([1, 2, 3])).toEqual([2, 4, 6]);
});
});
describe('arrayMul3', () => {
it('should return empty list if no numbers', () => {
expect(arrayMul3([])).toEqual([]);
});
it('should return multiplied numbers', () => {
expect(arrayMul3([1, 2, 3])).toEqual([3, 6, 9]);
});
});
});
xdescribe('FlatMap', () => {
describe('getLanguages', ()=> {
it('should return uniq languages', () => {
const cs = getLanguages(countries);
expect(cs.length).toEqual(29);
})
})
});
xdescribe('GroupBy', () => {
describe('getCountryByLanguages', ()=> {
it('should return country by language', () => {
const cs = getCountryByLanguages(countries);
console.log(cs)
expect(Object.keys(cs).length).toEqual(29);
})
})
})</script></body>
</html>
// noprotect
// Write your code here
// TESTS
describe('Loops vs Iteration', () => {
describe('isEven', () => {
it('1 is not even', () => {
expect(isEven(1)).toEqual(false);
});
it('2 is even', () => {
expect(isEven(2)).toEqual(true);
});
it('12 is even', () => {
expect(isEven(12)).toEqual(true);
});
it('should be slower', () => {
const startTime = +new Date();
const predicate = isEven(5);
const seconds = +new Date() - startTime;
expect(seconds).toBeGreaterThanOrEqual(clockSpeed);
});
});
xdescribe('getFirstEvens', () => {
it('should return empty list if empty', () => {
expect(getFirstEvens([], 1)).toEqual([]);
});
it('should return empty list if only odds', () => {
expect(getFirstEvens([1, 5], 2)).toEqual([]);
});
it('should return the first n evens', () => {
expect(getFirstEvens([1, 2, 4, 7, 8], 2)).toEqual([2, 4]);
});
it('should only check upto required n', () => {
const startTime = +new Date();
const firstEvens = getFirstEvens([2, 4, 6, 20, 4, 22], 2);
const seconds = +new Date() - startTime;
expect(firstEvens).toEqual([2, 4]);
expect(seconds).toBeLessThan(clockSpeed * 3);
});
})
});
xdescribe('Map / Filter / Reduce', () => {
xdescribe('Map with arrayMul2', () => {
it('should return empty list if no numbers', () => {
expect(arrayMul2([])).toEqual([]);
});
it('should return multiplied numbers', () => {
expect(arrayMul2([1, 2, 3])).toEqual([2, 4, 6]);
});
});
xdescribe('Filter with arrayEvens', () => {
it('should return empty list if no numbers', () => {
expect(arrayEvens([])).toEqual([]);
});
it('should return even numbers', () => {
expect(arrayEvens([1,3,5,62,4])).toEqual([62,4]);
});
});
xdescribe('Reduce with arraySum', () => {
it('should return zero if no numbers', () => {
expect(arraySum([])).toEqual(0);
});
it('should return sum when specified', () => {
expect(arraySum([1,2,3])).toEqual(6);
});
});
xdescribe('Reduce with arrayMul', () => {
it('should return one if empty', () => {
expect(arrayMul([])).toEqual(1);
});
it('should return product when specified', () => {
expect(arrayMul([1,2,3])).toEqual(6);
});
});
})
xdescribe('Curry', () => {
describe('arrayMul2', () => {
it('should return empty list if no numbers', () => {
expect(arrayMul2([])).toEqual([]);
});
it('should return multiplied numbers', () => {
expect(arrayMul2([1, 2, 3])).toEqual([2, 4, 6]);
});
});
describe('arrayMul3', () => {
it('should return empty list if no numbers', () => {
expect(arrayMul3([])).toEqual([]);
});
it('should return multiplied numbers', () => {
expect(arrayMul3([1, 2, 3])).toEqual([3, 6, 9]);
});
});
});
xdescribe('FlatMap', () => {
describe('getLanguages', ()=> {
it('should return uniq languages', () => {
const cs = getLanguages(countries);
expect(cs.length).toEqual(29);
})
})
});
xdescribe('GroupBy', () => {
describe('getCountryByLanguages', ()=> {
it('should return country by language', () => {
const cs = getCountryByLanguages(countries);
console.log(cs)
expect(Object.keys(cs).length).toEqual(29);
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment