0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paiza.ioでnode.js その4

Posted at

概要

paiza.ioでnode.js、やってみた。
練習問題やってみた。

練習問題

リストなタプルをソートせよ。

サンプルコード

process.stdin.resume();
process.stdin.setEncoding('utf8');

var rowElements = [{"timestamp":"1728082796491"},{"timestamp":"1728083796491","name":"ai","publish":"ture","condition":"good","comment":"ok"},{"timestamp":"1728083845078","name":"aita","publish":"1","condition":"good","comment":"ok"},{"timestamp":"1728082865943"},{"timestamp":"1728360810390","name":"test","comment":"iine"},{"timestamp":"1728362175611","name":"test","comment":"good"},{"timestamp":"1728082597520"},{"timestamp":"1728362004019","name":"test","comment":"last"},{"timestamp":"1728361668285","name":"test","comment":"こんにちは"},{"timestamp":"1728361943212","name":"test","comment":"良いね"}];

console.log(rowElements)

var target = [];

var result = Array.from(rowElements).sort(function(line1, line2) {
    return (line1.timestamp < line2.timestamp) ? -1 : 1;
});


for(var i = 0; i < result.length; i++)
{
   target.push(result[i]);
}

console.log(target)



[
  { timestamp: '1728082796491' },
  {
    timestamp: '1728083796491',
    name: 'ai',
    publish: 'ture',
    condition: 'good',
    comment: 'ok'
  },
  {
    timestamp: '1728083845078',
    name: 'aita',
    publish: '1',
    condition: 'good',
    comment: 'ok'
  },
  { timestamp: '1728082865943' },
  { timestamp: '1728360810390', name: 'test', comment: 'iine' },
  { timestamp: '1728362175611', name: 'test', comment: 'good' },
  { timestamp: '1728082597520' },
  { timestamp: '1728362004019', name: 'test', comment: 'last' },
  { timestamp: '1728361668285', name: 'test', comment: 'こんにちは' },
  { timestamp: '1728361943212', name: 'test', comment: '良いね' }
]
[
  { timestamp: '1728082597520' },
  { timestamp: '1728082796491' },
  { timestamp: '1728082865943' },
  {
    timestamp: '1728083796491',
    name: 'ai',
    publish: 'ture',
    condition: 'good',
    comment: 'ok'
  },
  {
    timestamp: '1728083845078',
    name: 'aita',
    publish: '1',
    condition: 'good',
    comment: 'ok'
  },
  { timestamp: '1728360810390', name: 'test', comment: 'iine' },
  { timestamp: '1728361668285', name: 'test', comment: 'こんにちは' },
  { timestamp: '1728361943212', name: 'test', comment: '良いね' },
  { timestamp: '1728362004019', name: 'test', comment: 'last' },
  { timestamp: '1728362175611', name: 'test', comment: 'good' }
]

成果物

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?