Sha256: 7e639fd0dfa158cf593c2c23cd38531e9f55872e49a8ef0411cd2f6ce2b03468

Contents?: true

Size: 641 Bytes

Versions: 207

Compression:

Stored size: 641 Bytes

Contents

struct BracketPush {

    private static let brackets: [Character : Character] = [
        ")": "(",
        "]": "[",
        "}": "{"
    ]

    static func paired(text: String) -> Bool {
        var stack = [Character]()

        for character in text.characters {
            if brackets.values.contains(character) {
                stack.append(character)
            } else if brackets.keys.contains(character) {
                guard let last = stack.popLast(),
                    last == brackets[character] else {
                        return false
                }
            }
        }

        return stack.isEmpty
    }
}

Version data entries

207 entries across 207 versions & 1 rubygems

Version Path
trackler-2.2.1.60 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.59 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.58 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.57 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.56 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.55 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.54 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.53 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.52 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.51 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.50 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.49 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.48 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.47 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.46 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.45 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.44 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.43 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.42 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.2.1.41 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift