Skip to content

Instantly share code, notes, and snippets.

@dxcqcv
dxcqcv / description.txt
Created January 9, 2024 12:36 — forked from mr-parus/description.txt
[JS] Alphabetic Anagrams
Task from Codewars: https://www.codewars.com/kata/53e57dada0cb0400ba000688/train/javascript
Consider a "word" as any sequence of capital letters A-Z (not limited to just "dictionary words"). For any word with at least two different letters, there are other words composed of the same letters but in a different order (for instance, STATIONARILY/ANTIROYALIST, which happen to both be dictionary words; for our purposes "AAIILNORSTTY" is also a "word" composed of the same letters as these two).
We can then assign a number to every word, based on where it falls in an alphabetically sorted list of all words made up of the same group of letters. One way to do this would be to generate the entire list of words and find the desired one, but this would be slow if the word is long.
Given a word, return its number. Your function should be able to accept any word 25 letters or less in length (possibly with some letters repeated), and take no more than 500 milliseconds to run. To compare, when the solution code runs the 2
@dxcqcv
dxcqcv / pubsub.js
Last active May 21, 2017 08:21
Publish/Subscriber pattern
const pubsub = (function(){
let topics = {};
let subUid = -1;
let oneId = '';
function publish(topic, args) {
if(!topics[topic]) return false;
let subscribers = topics[topic],
len = subscribers ? subscribers.length : 0;
var Subject = function() {
var observers = [];
return {
subscribeObserver: function(observer) {
observers.push(observer);
},
unsubscribeObserver: function(observer) {
def foo
111
rescue
222
ensure
333
end
puts foo # got 111, why????