Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

https://192.168.178.36/index2.htm

/* Simple Hello World in Node.js */
console.log("Hello World");

ASDSDASAD

function sortNumber(a,b) {
        return a - b;
    }

starries = 5
lannies = 152
targies = 72

numbers = [starries, lannies, targies]
console.log("Numbers unsorted")
console.log(numbers)

numbers.sort(sortNumber)
//THIS IS IMPORTANT//
numbers.reverse()
////////////////////


console.log("Numbers sorted")
console.log(numbers)


///////THIS IS ALSO IMPORTANT
finisheddescription = []

numbers.forEach(function(element) {
  if (element == starries) {
      finisheddescription.push("Starries: " + element.toLocaleString("en"))
  } else if (element == lannies) { 
      finisheddescription.push("lannies: " + element.toLocaleString("en"))
  } else if (element == targies) {
      finisheddescription.push("targies: " + element.toLocaleString("en"))
  }
});

console.log(finisheddescription.join("\n"))

obama

var stdin = process.openStdin();
var data = [];
var letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
var BCTABNTb_TEKCT = `2
103 31
217 1891 4819 2291 2987 3811 1739 2491 4717 445 65 1079 8383 5353 901 187 649 1003 697 3239 7663 291 123 779 1007 3551 1943 2117 1679 989 3053
10000 25
3292937 175597 18779 50429 375469 1651121 2102 3722 2376497 611683 489059 2328901 3150061 829981 421301 76409 38477 291931 730241 959821 1664197 3057407 4267589 4729181 5335543`;
data = BCTABNTb_TEKCT.toString().split(/\r\n|\r|\n/);
var tests = data[0];
for(var i = 0; i<tests; i++) {
    var s1 = data[i*2+1].split(' ');
    var s2 = data[i*2+2].split(' ').reverse();
    var lastPrime = parseInt(s1[0]);
    var primesCount = parseInt(s1[1]);
    
    var givenPrimes = s2;
    
    var sourceList = [];
    
    var tempList = [];
    
    for(var j = 0; j<primesCount; j++) {
        var n = s2[j];
        var nums = findPrimes(n);
        if(nums.length == 1) {
            nums.push(n/nums[0]);
        }
        tempList.push(nums);
    }
    for(var k = 0; k<primesCount; k++) {
        if(k>0) {
            var arr1 = tempList[k];
            var arr2 = tempList[k-1];
            
            var sameArr = arr1.filter(element => arr2.includes(element));
            var same = sameArr[0];
            if(arr2[0] == same) sourceList.push(arr2[1]);
            else sourceList.push(arr2[1]);
            sourceList.push(same);
            if(k==primesCount-1) {
                if(arr1[0] == same) sourceList.push(arr1[1]);
                else sourceList.push(arr1[0]);
            }
        }
    }
    for(var m = 0; m<sourceList.length; m++) {
        if(sourceList[m] == sourceList[m+1]) {
            sourceList.splice(m+1, 1);
            m--;
        }
    }
    
    sourceList.reverse();
    
    var sorted = sourceList.filter((v,i) => sourceList.indexOf(v) == i);
    sorted.sort((a, b) => a - b);
    
    var msg = [];
    
    for(var h = 0; h<sourceList.length; h++) {
        for(var p = 0; p<sorted.length; p++) {
            if(sorted[p] == sourceList[h]) msg.push(letters[p]);
        }
    }
    console.log('Case #'+(i+1)+': '+msg.join(''));
}

function findPrimes(num) {
    var integer = num,
    primeArray = [],
    isPrime;

    for(i = 2; i <= integer; i++){
      if (integer % i==0) {
        for(var j = 2; j <= i/2; j++) {
          if(i % j == 0) {
            isPrime = false;
          } else {
            isPrime = true;
          }
        }
    
        if (isPrime == true) {
          integer /= i
          primeArray.push(i);
        }
      }   
    }
    
    var result = [];
    for (var k = 0; k < primeArray.length; k++) {
      result.push(primeArray[k]);
    }
    
    return result;
}

Promise test

/* Simple Hello World in Node.js */
console.log("Hello World");

let a =  new Promise((res, rej) => {
    res('Winning!');
});

b = a.then(
    (res) => {console.log('Resolve in B'); return new Promise((res, rej) => {
    rej('Winning!');
});},
    (rej) => {console.log('Reject in B');}
);

c = b.then(
    (res) => {console.log('Resolve in C');},
    (rej) => {console.log('Reject in C')}
);

d = c.then(
    (res) => {console.log('Resolve in D')},
    (rej) => {console.log('Reject in D')}
);

d.catch(
    (rej) => {console.log('Caught in the catch')}
);

/*
Once a Promise is fulfilled or rejected, the respective handler function (onFulfilled or onRejected) will be called asynchronously (scheduled in the current thread loop). The behavior of the handler function follows a specific set of rules. If a handler function:

 - returns a value, the promise returned by then gets resolved with the returned value as its value;
 - doesn't return anything, the promise returned by then gets resolved with an undefined value;
 - throws an error, the promise returned by then gets rejected with the thrown error as its value;
 - returns an already fulfilled promise, the promise returned by then gets fulfilled with that promise's value as its value;
 - returns an already rejected promise, the promise returned by then gets rejected with that promise's value as its value;
 - returns another pending promise object, the resolution/rejection of the promise returned by then will be subsequent to the resolution/rejection of the promise returned by the handler. Also, the value of the promise returned by then will be the same as the value of the promise returned by the handler.
*/

Execute Node.js Online

let course_name = 'ICT4510';
console.log(course_name);
const TAX_RATE = 28.0;
console.log(TAX_RATE);

Node.js Hello World Example

const os = require('os');

var dealTime = (seconds)=>{
    var seconds = seconds|0;
    var day = (seconds/(3600*24))|0;
    var hours = ((seconds-day*3600)/3600)|0;
    var minutes = ((seconds-day*3600*24-hours*3600)/60)|0;
    var second = seconds%60;
    (day<10)&&(day='0'+day);
    (hours<10)&&(hours='0'+hours);
    (minutes<10)&&(minutes='0'+minutes);
    (second<10)&&(second='0'+second);
    return [day,hours,minutes,second].join(':');
};

var dealMem = (mem)=>{
    var G = 0,
        M = 0,
        KB = 0;
    (mem>(1<<30))&&(G=(mem/(1<<30)).toFixed(2));
    (mem>(1<<20))&&(mem<(1<<30))&&(M=(mem/(1<<20)).toFixed(2));
    (mem>(1<<10))&&(mem>(1<<20))&&(KB=(mem/(1<<10)).toFixed(2));
    return G>0?G+'G':M>0?M+'M':KB>0?KB+'KB':mem+'B';
};

//cpu架构
const arch = os.arch();
console.log("cpu架构:"+arch);

//操作系统内核
const kernel = os.type();
console.log("操作系统内核:"+kernel);

//操作系统平台
const pf = os.platform();
console.log("平台:"+pf);

//系统开机时间
const uptime = os.uptime();
console.log("开机时间:"+dealTime(uptime));

//主机名
const hn = os.hostname();
console.log("主机名:"+hn);

//主目录
const hdir = os.homedir();
console.log("主目录:"+hdir);


//内存
const totalMem = os.totalmem();
const freeMem = os.freemem();
console.log("内存大小:"+dealMem(totalMem)+' 空闲内存:'+dealMem(freeMem));

//cpu
const cpus = os.cpus();
console.log('*****cpu信息*******');
cpus.forEach((cpu,idx,arr)=>{
    var times = cpu.times;
    console.log(`cpu${idx}:`);
    console.log(`型号:${cpu.model}`);
    console.log(`频率:${cpu.speed}MHz`);
    console.log(`使用率:${((1-times.idle/(times.idle+times.user+times.nice+times.sys+times.irq))*100).toFixed(2)}%`);
});

//网卡
console.log('*****网卡信息*******');
const networksObj = os.networkInterfaces();
for(let nw in networksObj){
    let objArr = networksObj[nw];
    console.log(`\r\n${nw}:`);
    objArr.forEach((obj,idx,arr)=>{
        console.log(`地址:${obj.address}`);
        console.log(`掩码:${obj.netmask}`);
        console.log(`物理地址:${obj.mac}`);
        console.log(`协议族:${obj.family}`);
    });
}

Node.js Hello World Example

console.log('erwer');

demo

/* Hello, World! program in node.js */
console.log("Hello, World!")

AGHDFDFGDG

var os = require("os");

// Endianness
console.log('endianness : ' + os.endianness());

// OS type
console.log('type : ' + os.type());

// OS platform
console.log('platform : ' + os.platform());

// Total system memory
console.log('total memory : ' + os.loadavg() + " bytes.");

// Total free memory
console.log('free memory : ' + os.loadavg() + " bytes.");

console.log(os.totalmem())

Execute Node.js Online

const https = require('https');
var request = require('sync-request');

var dictionary_key = "dict.1.1.20190324T215034Z.b42d9046a9fc4903.e8ea2f4864d4cd4db4b5bec3aa57c56fce83f449";

var dictionary = "https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key=" + dictionary_key + "&lang=en-de&text=";


var httpRequest = function (a){
    var adress = dictionary + a
https.get(adress, (resp) => {
  let data = '';

  // A chunk of data has been recieved.
  resp.on('data', (chunk) => {
    data += chunk;
  });

  // The whole response has been received. Print out the result.
  resp.on('end', () => {
    console.log(data + "here is HTTP request");                  //console log recieved data
    return data
  });

}).on("error", (err) => {
  console.log("Error: " + err.message);
})};

var httpRequestSync = function (a){
  var adress = dictionary +a;
  var res = request('GET', adress);
  var resConverted = res.getBody()
  console.log(resConverted + "here is http request");
  return resConverted
}

var splitString = function (txt, at){
    return txt.split(at)
};
var getAPI = function(b){
    var arr = [];
    for (var i = 0; i<b.length; i++ ){
        arr.push(httpRequestSync(b[i]))
    }
    console.log(arr+ "here is getApi")                    //console log the recieved objects
    return arr
};
var newWord = function (a,b){
    var str = "";
    var tag ="";
    str = a.text + ";" ; //English word
    str = str + a.pos + ";" ; //position
    str = str + b.text + ";"; //German word
    str = str + b.pos + tag +"\n\r"; //position +(tag)+ newline
    return str
};
var createOutput = function(input){
    var outp = "";
    for (var k = 0; k < input.length; k++){//for each searched word
        for(var l = 0;l< input[k].def.length; l++){//for each definition of word
            for(var m=0; m<input[k].def[l].tr.length;m++){//for each translation of word definition
                var definition = input[k].def[l];
                var translation = input[k].def[l].tr[m];
                outp = outp + newWord(defintion, translation)
            }
        }
    }
    return outp
};




var doIt = function (words) {
    
    var wordsArr = splitString(words, ",");
    var responseArr = getAPI(wordsArr);
    var anki = createOutput(responseArr);
    console.log(anki)
    
};

var textToTranslate = "wracked,dispensed,despair"; //Enter text here

doIt(textToTranslate);


{"head":{},"def":[]},{"head":{},"def":[]},{"head":{},"def":[{"text":"despair","pos":"noun","ts":"dɪsˈpɛə","tr":[{"text":"Verzweiflung","pos":"noun","gen":"f","mean":[{"text":"desperation"}]}]},{"text":"despair","pos":"verb","ts":"dɪsˈpɛə","tr":[{"text":"verzweifeln","pos":"verb","mean":[{"text":"desperation"}]}]}]}


1 2 3 4 5 6 7 ... 90 Next
Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.