async function a() { return 'ok' } async function b() { try { const res = await a() console.log(res) } catch(e) { console.log(e) } }
function a() {return new Promise(function (resolve, reject) {resolve('ok');});- async function a() {
- return 'ok'
- }
function b() {a().then(function(res) {console.log(res);}).catch(function(err) {console.log(err);})- async function b() {
- try {
- const res = await a()
- console.log(res)
- } catch(e) {
- console.log(e)
- }
- }
function monteCarlo() { return new Promise(function (resolve, reject) { reject({server: 'down'}); }); } async function main() { try { const results = await monteCarlo(); } catch(e) { console.log(e) } return true; }
- function monteCarlo() {
- return new Promise(function (resolve, reject) {
- reject({server: 'down'});
- });
- }
- async function main() {
// converter para ES6const results = await monteCarlo();- try {
- const results = await monteCarlo();
- } catch(e) {
- console.log(e)
- }
- return true;
- }
function monteCarlo() { return new Promise(function (resolve, reject) { resolve([{ titulo: 'UOL - O Melhor conteúdo' }]); }); } async function main() { const response = await monteCarlo() return true; }
- function monteCarlo() {
- return new Promise(function (resolve, reject) {
- resolve([{
- titulo: 'UOL - O Melhor conteúdo'
- }]);
- });
- }
- async function main() {
// converter para ES6monteCarlo().then(function(response) {console.log(response)});- const response = await monteCarlo()
- return true;
- }
const main = () => { let links = [ 'https://www.uol', 'https://www.bol.com.br', 'https://www.uol', 'https://noticias.uol.com.br', 'https://www.bol.com.br', ]; // converter para ES6 var uniqueLinks = links.reduce(function (carry, item) { if (carry.indexOf(item) === -1) { carry.push(item); } return carry; }, []); return new Set(links); };
- const main = () => {
- let links = [
- 'https://www.uol',
- 'https://www.bol.com.br',
- 'https://www.uol',
- 'https://noticias.uol.com.br',
- 'https://www.bol.com.br',
- ];
- // converter para ES6
- var uniqueLinks = links.reduce(function (carry, item) {
- if (carry.indexOf(item) === -1) {
- carry.push(item);
- }
- return carry;
- }, []);
return uniqueLinks.length;- return new Set(links);
- };
// TODO: Add your tests here // Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework. // [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework) // are still available for now. // // For new tests, using [Chai](https://chaijs.com/) is recommended. // You can use it by requiring: // const assert = require("chai").assert; // If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted. describe("Solution", function() { it("should test for something", function() { // Test.assertEquals(1 + 1, 2); // assert.strictEqual(1 + 1, 2); }); });
- // TODO: Add your tests here
- // Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
- // [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
- // are still available for now.
- //
- // For new tests, using [Chai](https://chaijs.com/) is recommended.
- // You can use it by requiring:
- // const assert = require("chai").assert;
- // If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
- describe("Solution", function() {
- it("should test for something", function() {
- // Test.assertEquals(1 + 1, 2);
- // assert.strictEqual(1 + 1, 2);
- });
- });
const main = () => { let a = [1, 2, 3]; let b = [4, 5, 6]; let c = [7, 8, 9]; // converter para ES6 var d = [...a, ...b, ...c] return d.join(','); }
- const main = () => {
- let a = [1, 2, 3];
- let b = [4, 5, 6];
- let c = [7, 8, 9];
- // converter para ES6
var d = a.concat(b).concat(c);- var d = [...a, ...b, ...c]
- return d.join(',');
- }
class Component { constructor(dom) { console.log('Parent class constructor executed!'); this.dom = dom; } onCreate() { return true; } } class Collection extends Component { constructor(dom) { super(dom); } }
- class Component {
- constructor(dom) {
- console.log('Parent class constructor executed!');
- this.dom = dom;
- }
- onCreate() {
- return true;
- }
- }
class Collection {//- class Collection extends Component {
- constructor(dom) {
- super(dom);
- }
- }
class Component { constructor(dom) { this.dom = dom; } onCreate() { console.log('onCreate from parent class'); return 'missing'; } static on(event, callback) { callback(); } async emit(event, data) {} } class Title extends Component { onCreate(){ super.onCreate(); return 'super!'; } }
- class Component {
- constructor(dom) {
- this.dom = dom;
- }
- onCreate() {
- console.log('onCreate from parent class');
- return 'missing';
- }
- static on(event, callback) {
- callback();
- }
- async emit(event, data) {}
- }
- class Title extends Component {
- onCreate(){
- super.onCreate();
- return 'super!';
- }
- }
var bg = `gray`; var css = ` <style> body { background: ${bg}; color: black; } </style>`;
var bg = 'gray';- var bg = `gray`;
var css = '' +'<style>' +'body {' +' background: '+ bg + ';' +' color: black;''}' +'</style>';- var css = ` <style>
- body {
- background: ${bg};
- color: black;
- }
- </style>`;