Last active
July 31, 2018 10:43
-
-
Save guillaumegarcia13/9299d6d05b1ebd8a073b67504c97b970 to your computer and use it in GitHub Desktop.
Yield example
This file contains hidden or 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
// Run it live on: https://goo.gl/dgwE2D | |
class Example { | |
public getCountries(fields: string[] = ['name', 'alpha2Code', 'translations', 'flag']): Observable<any[]> { | |
const sep = (function* () { | |
let call = 0; | |
while (true) { | |
yield (call++ === 0) ? '?' : '&'; | |
} | |
})(); | |
const url = `https://restcountries.eu/rest/v2/all` | |
+ | |
((fields && fields.length > 0) ? sep.next().value + 'fields=' + fields.join(';') | |
: '') | |
; | |
return url; | |
} | |
} | |
const y = new Example(); | |
document.write('<a href="'+y.getCountries()+'">'+y.getCountries()+'</a>'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment