mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-10 16:00:36 +08:00
* Retranslate the complete English edition from Simplified Chinese * Polish three English explanations after reader-focused review
36 lines
723 B
JavaScript
36 lines
723 B
JavaScript
/**
|
|
* File: Vertex.js
|
|
* Created Time: 2023-02-15
|
|
* Author: Zhuo Qinyue (1403450829@qq.com)
|
|
*/
|
|
|
|
/* Vertex class */
|
|
class Vertex {
|
|
val;
|
|
constructor(val) {
|
|
this.val = val;
|
|
}
|
|
|
|
/* Given the list of values vals, return the list of vertices vets */
|
|
static valsToVets(vals) {
|
|
const vets = [];
|
|
for (let i = 0; i < vals.length; i++) {
|
|
vets[i] = new Vertex(vals[i]);
|
|
}
|
|
return vets;
|
|
}
|
|
|
|
/* Given the list of vertices vets, return the list of values vals */
|
|
static vetsToVals(vets) {
|
|
const vals = [];
|
|
for (const vet of vets) {
|
|
vals.push(vet.val);
|
|
}
|
|
return vals;
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
Vertex,
|
|
};
|