JSFiddle - React, Tailwind, and code Playground

Input and Sort Array

by Hugo Carneiro

JavaScript

function sort(input) {
	return Promise.resolve(input.sort((a, b) => a - b));
}

const promise = new Promise((resolve, reject) => {
	const data = prompt('Please type a JSON array');
  let parsed;

  if (!data) {
  	return reject('Please type a JSON array');
  }
	
  try {
  	debugger;
		parsed = JSON.parse(data);
  } catch (e) {
  	return reject('Input is not a valid JSON');
  }

  if (!Array.isArray(parsed)) {
  	return reject('Input is not a valid array');
  }
  
  resolve(sort(parsed));
});


promise
	.then(console.log)
  .catch(console.error);