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.0.6.42 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.41 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.40 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.39 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.38 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.37 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.36 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.35 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.34 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.33 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.32 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.31 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.30 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.29 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.28 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.27 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.26 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.25 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.24 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift
trackler-2.0.6.23 tracks/swift/exercises/bracket-push/Sources/BracketPushExample.swift