Revision 2cd44438-c255-424f-a233-c477d65ac6bc - Code Golf Stack Exchange

##JavaScript (ES6), <s>91</s> <s>89</s> 87 bytes

*Saved 2 bytes thanks to Ismael Miguel*

 s=>(k=0,[...s].reduce((p,c,i)=>(k+=p>c?1<<i:0/(p<c),c)),k?!(k%3)&&!s[5]&&s[0]==s[4]:!1)

###How it works

We build a 4-bit bitmask `k` representing the 4 transitions between the 5 characters of the string:

 k += p > c ? 1<<i : 0 / (p < c)

 - if the previous character is higher than the next one, the bit is set
 - if the previous character is lower then the next one, the bit is not set
 - if the previous character is identical to the next one, the whole bitmask is forced to `NaN` so that the word is rejected (to comply with rule #6)

The valid bitmasks are the ones that have exactly two consecutive `1` transitions (the first and the last bits being considered as *consecutive* as well):

 Binary | Decimal
 -------+--------
 0011 | 3
 0110 | 6
 1100 | 12
 1001 | 9

In other words, these are the combinations which are:

 - `k?` : greater than 0
 - `!(k%3)` : **congruent to 0 modulo 3**
 - lower than 15

The other conditions are:

- `!s[5]` : there's no more than 5 characters
- `s[0]==s[4]` : the 1st and the 5th characters are identical

**NB**: We don't explicitly check `k != 15` because any word following such a pattern will be rejected by this last condition.

###Test cases

<!-- begin snippet: js hide: true console: true babel: false -->

<!-- language: lang-js -->

 let f =

 s=>(k=0,[...s].reduce((p,c,i)=>(k+=p>c?1<<i:0/(p<c),c)),k?!(k%3)&&!s[5]&&s[0]==s[4]:!1)

 console.log("Testing truthy words...");
 console.log(f("ALPHA"));
 console.log(f("EAGLE"));
 console.log(f("HARSH"));
 console.log(f("NINON"));
 console.log(f("PINUP"));
 console.log(f("RULER"));
 console.log(f("THEFT"));
 console.log(f("WIDOW"));

 console.log("Testing falsy words...");
 console.log(f("CUBIC"));
 console.log(f("ERASE"));
 console.log(f("FLUFF"));
 console.log(f("LABEL"));
 console.log(f("MODEM"));
 console.log(f("RADAR"));
 console.log(f("RIVER"));
 console.log(f("SWISS"));
 console.log(f("TRUST"));
 console.log(f("KNEES"));
 console.log(f("QUEEN"));
 console.log(f("ORTHO"));
 console.log(f("GROOVE"));
 console.log(f("ONLY"));
 console.log(f("CHARACTER"));
 console.log(f("OFF"));
 console.log(f("IT"));
 console.log(f("ORTHO"));

<!-- end snippet -->

###Initial version

For the record, my initial version was 63 bytes. It's passing all test cases successfully but fails to detect consecutive identical characters.

 ([a,b,c,d,e,f])=>!f&&a==e&&!(((a>b)+2*(b>c)+4*(c>d)+8*(d>e))%3)

Below is a 53-byte version suggested by Neil in the comments, which works (and fails) equally well:

 ([a,b,c,d,e,f])=>!f&&a==e&&!((a>b)-(b>c)+(c>d)-(d>e))

**Edit:** See [Neil's answer][1] for the fixed/completed version of the above code.


 [1]: https://codegolf.stackexchange.com/a/96568/58563

AltStyle によって変換されたページ (->オリジナル) /