mirror of https://github.com/01-edu/public.git
2 changed files with 66 additions and 0 deletions
@ -0,0 +1,42 @@
|
||||
import fs from 'fs/promises' |
||||
const readFile = fs.readFile |
||||
const writeFile = fs.writeFile |
||||
import { promisify } from 'util' |
||||
import * as cp from 'child_process' |
||||
|
||||
const exec = promisify(cp.exec) |
||||
|
||||
export const tests = [] |
||||
const name = 'verydisco-reverso' |
||||
const hasContentAndExpect = async ({ content, expect, path, eq }) => { |
||||
const cwd = `${path |
||||
.split('/') |
||||
.slice(0, -1) |
||||
.join('/')}/` |
||||
|
||||
await writeFile(`${cwd}${name}.txt`, content, 'utf8') |
||||
const { stdout } = await exec(`node ${name}.mjs "${name}.txt"`, { cwd }) |
||||
await exec(`rm ${name}.txt`, { cwd }) |
||||
|
||||
return eq(stdout.trim(), expect) |
||||
} |
||||
|
||||
tests.push(async ({ path, eq }) => |
||||
hasContentAndExpect({ |
||||
path, |
||||
eq, |
||||
content: `deNo si omeawes`, |
||||
expect: 'Node is awesome', |
||||
}), |
||||
) |
||||
|
||||
// tests.push(async ({ path, eq }) => {
|
||||
// await hasContentAndExpect({
|
||||
// path,
|
||||
// eq,
|
||||
// content: // newfilename,
|
||||
// expect: // reverso
|
||||
// })
|
||||
// })
|
||||
|
||||
Object.freeze(tests) |
@ -0,0 +1,24 @@
|
||||
## verydisco-reverso |
||||
|
||||
### Instructions |
||||
|
||||
Create a `verydisco-reverso.mjs` script that: |
||||
- takes the name of a file (with extension) in argument |
||||
- read this file |
||||
- discover the content of this file by reversing it from the `very disco` mode |
||||
- print the result in console |
||||
|
||||
For example: |
||||
- Reading the `verydisco` content of your `verydisco.txt` file would print `discovery` in console. |
||||
|
||||
### Notions |
||||
|
||||
- [Node file system: `readFile`](https://nodejs.org/api/fs.html#fs_fspromises_writefile_file_data_options) |
||||
<!-- and also Math.floors ? --> |
||||
<!-- |
||||
again? |
||||
- [Node path: `resolve`](https://nodejs.org/api/path.html#path_path_resolve_paths) |
||||
- [Node path: `join`](https://nodejs.org/api/path.html#path_path_join_paths) |
||||
--> |
||||
|
||||
|
Loading…
Reference in new issue