How to add Live Template in Webstorm
- open preferences
- editor> live templates
- add template group for React Native
- add templates below to the new group
- define context > javascript
- edit variables > add "fileNameWithoutExtension" to "$fnName$"
The context is a long running server side calculation. Because of this long running necessity, we can not use the default request/response, but need to handle it asynchronously.
We have 3 api endpoints available to implement this asynchronous result calculation.
Pluralize or singular string based on a number
Handlebars.registerHelper('pluralize', function(number, singular, plural) {
if (number === 1) {
return singular;
} else {
return (typeof plural === 'string' ? plural : singular + 's');
}
});
function fib(end) { | |
const range = [0, 1]; | |
while (range[range.length - 1] < end) { | |
const prev = range[range.length - 1]; | |
const prevPrev = range[range.length - 2]; | |
range.push(prev + prevPrev); | |
} | |
return range; |
/* | |
* Outputs a float representing the iOS version if user is using an iOS browser i.e. iPhone, iPad | |
* Possible values include: | |
* 3 - v3.0 | |
* 4.0 - v4.0 | |
* 4.14 - v4.1.4 | |
* false - Not iOS | |
*/ | |
var iOS = parseFloat( |