DOC: ns.scan(): add 2 examples

The first example shows how to use `ns.scan()` without passing an argument.  The second example uses `ns.scan()` by passing the hostname of a target server.  Both examples can be written more succinctly by using the `forEach()` method of array, but for the purposes of illustration the `for` loop should be easier for beginners to read.
This commit is contained in:
Duck McSouls
2022-10-11 18:48:47 +11:00
parent 67f5d60116
commit b03288a700

View File

@@ -5156,6 +5156,41 @@ export interface NS {
* node way from the specified target server. The hostnames in the returned
* array are strings.
*
* @example
* ```ts
* // NS1
* // All servers that are one hop from the current server.
* tprint("Neighbors of current server.");
* var neighbor = scan();
* for (var i = 0; i < neighbor.length; i++) {
* tprint(neighbor[i]);
* }
* // All neighbors of n00dles.
* var target = "n00dles";
* neighbor = scan(target);
* tprintf("Neighbors of %s.", target);
* for (var i = 0; i < neighbor.length; i++) {
* tprint(neighbor[i]);
* }
* ```
* @example
* ```ts
* // NS2
* // All servers that are one hop from the current server.
* ns.tprint("Neighbors of current server.");
* let neighbor = ns.scan();
* for (let i = 0; i < neighbor.length; i++) {
* ns.tprint(neighbor[i]);
* }
* // All neighbors of n00dles.
* const target = "n00dles";
* neighbor = ns.scan(target);
* ns.tprintf("Neighbors of %s.", target);
* for (let i = 0; i < neighbor.length; i++) {
* ns.tprint(neighbor[i]);
* }
* ```
*
* @param host - Optional. Hostname of the server to scan, default to current server.
* @returns Returns an array of hostnames.
*/