{ "palindrome": { "0": "a", "length":"1000", "999":"a" } }
|
创建一个对象,对象的length是1000
然后给0和999填数据,得到flag
const validatePalindrome = (string) => { if (string.length < 1000) { return 'too short'; }
for (const i of Array(string.length).keys()) { const original = string[i]; const reverse = string[string.length - i - 1]; if (original !== reverse || typeof original !== 'string') { return 'not palindrome'; } }
return null; }
|
善于调试
Keys of Array: [ 0 ] Index: 0, Original: a, Reverse: a, Type of Original: string
|
const express = require('express'); const bodyParser = require('body-parser');
const app = express(); app.use(bodyParser.json());
const validatePalindrome = (string) => { if (string.length < 1000) { return 'too short'; } console.log(`String: ${string}, Length: ${string.length}`); for (const i of Array(string.length).keys()) {
const original = string[i]; const reverse = string[string.length - i - 1]; const keysArray = [...Array(string.length).keys()]; console.log(`Keys of Array:`, keysArray);
console.log(`Index: ${i}, Original: ${original}, Reverse: ${reverse}, Type of Original: ${typeof original}`); if (original !== reverse || typeof original !== 'string') { return 'not palindrome'; } }
return 'It is a palindrome!'; }
app.post('/', (req, res) => { const result = validatePalindrome(req.body.palindrome); res.send(result); });
app.listen(3000, () => { console.log('Server running on http://localhost:3000'); });
|