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 decodeMorse = (morseCode) => { | |
return morseCode | |
.trim() | |
.split(/ | /) | |
.map( (code) => MORSE_CODE[code] || ' ') | |
.join(''); | |
} |
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
describe("GIVEN a call to decodeMorse", () => { | |
[... additional tests to cover non-edge cases ...] | |
it('THEN it decodes the special SOS code', () => { | |
Test.assertEquals(decodeMorse('...---...'), 'SOS'); | |
}); | |
it('THEN it decodes the special = code', () => { | |
Test.assertEquals(decodeMorse('-...-'), '='); | |
}); | |
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 decodeMorse = (morseCode) => { | |
// Morse words are separated by 3 spaces | |
const morseWords = morseCode.trim().split(' '); | |
return morseWords.map(morseWordToEnglishWord).join(' '); | |
} | |
const morseWordToEnglishWord = (morseWord) => { | |
// Morse letters are separated by 1 space | |
const morseLetters = morseWord.split(' '); | |
return morseLetters.map(morseLetterToEnglishLetter).join(''); |
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
return morseWords.map(morseWordToEnglishWord).join(' '); |
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
// Morse letters are separated by 1 space | |
const morseLetters = morseWord.split(' '); |
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
split(/ | /) |
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 code = '..-. --- --- -... .- .-.'; //FOO BAR |
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 decodeMorse = (morseCode) => { | |
return morseCode | |
.trim() | |
// Each Morse code words are split by 3 spaces, and each letters are split by 1 space. | |
// The order of the two sequences below is important. We always check for 2 spaces first | |
// and then for one space. This allows to split all letters properly because 2 spaces | |
// will not match one space. If we do hit a 3 spaces sequence, we will first split on | |
// the 2 spaces, which will leave us with a right substring starting with 1 space. | |
// This will then be split again because of the trailing space. The 3 spaces will then | |
// result in 3 substrings. The expected left substring letter, an empty string, and the |
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
import * as apigateway from "@pulumi/aws-apigateway"; | |
import * as aws from "@pulumi/aws"; | |
export const api = new apigateway.RestAPI("pulumi-serverless-journey", { | |
stageName: "dev", | |
routes: [ | |
{ | |
path: "/function1", | |
method: "POST", | |
eventHandler: new aws.lambda.CallbackFunction("function1", { |
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
import { createFunctionHandler } from "@resources/createFunctionHandler"; | |
import type { AWS } from "@serverless/typescript"; | |
const serverlessConfiguration: AWS = { | |
service: "pulumi-serverless-journey", | |
frameworkVersion: "3", | |
provider: { | |
name: "aws", | |
runtime: "nodejs14.x", | |
region: "us-east-1", |
OlderNewer