This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Subject = function() { | |
var observers = []; | |
return { | |
subscribeObserver: function(observer) { | |
observers.push(observer); | |
}, | |
unsubscribeObserver: function(observer) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def foo | |
111 | |
rescue | |
222 | |
ensure | |
333 | |
end | |
puts foo # got 111, why???? |