خرید بک لینک

Vote count: 0

Question: How do i sort an already existing list and print it sorted? For example if the list is unsorted (contains name, city, height) and i want to sort it by height. I hope u'll understand what i mean :(

i hope this will help.

var fs = require('fs');
var chalk = require('chalk');
var color = require('colors');

//read unsorted list

fs.readFile('../test.json', function(err, data){
if(err) {
  console.log('Error: ' + err);
  retu;
   };

// is this how i write a file and sort its data at the same time?

fs.writeFile('../test_sorted', 'SOMETHING_THAT_SORTS???', function (err,data) {
if (err) {
retu console.log(err);
}
  console.log(data);
});

  var objekt = JSON.parse(data);

//print sorted list

console.log('_-¯-_-¯-_-¯-_-¯-_-¯-_-¯-_-¯-_-¯-_-¯-_-¯-_')
for(var i=0; i<objekt.test_sorted.length; i++){
console.log(chalk.bgWhite.black('| Name: ' + objekt.test_sorted[i]['name']));
console.log(chalk.bgMagenta.white('| City: ' + objekt.test_sorted[i]['city']));
console.log(chalk.bgCyan.black('| Height: ' + objekt.test_sorted[i]['height'] + 'm'));
console.log('_-¯-_-¯-_-¯-_-¯-_-¯-_-¯-_-¯-_-¯-_-¯-_-¯-_')
  }
});

an example of a test.json could be smth like

{
 "test":[
 {
    "name":"Burgertown"
    "city":"fuy"
    "height":"20"
 }
 {
    "name":"pizzatown"
    "city":"triedtobefuy"
    "height":"24"
 }

... and so on

asked 54 secs ago

برچسب: نویسنده: استخدام کار تاريخ: جمعه 10 ارديبهشت 1395 ساعت: 1:15

صفحه بندی