Skip to content

Instantly share code, notes, and snippets.

@daxxog
Created February 23, 2020 00:53
Show Gist options
  • Save daxxog/12447d133eb80b90592117ddf0189cf5 to your computer and use it in GitHub Desktop.
Save daxxog/12447d133eb80b90592117ddf0189cf5 to your computer and use it in GitHub Desktop.
generator for palindrome case statements
const c4se = function(n) {
const varname = 'string_x';
var buildCase = '';
console.log('case ' + n + ':');
for(var i = 0; i<~~(n/2); i++) {
buildCase += '(string_x[' + i + '] === ' + 'string_x[' + (n - i - 1) + '])';
}
console.log(' return ' + buildCase.split(')(').join(')&&(') + ';');
};
for(var i = 0; i<50; i++) {
c4se(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment