let stdout = ProcessInfo.processInfo.environment["OUTPUT_PATH"]!
FileManager.default.createFile(atPath: stdout, contents: nil, attributes: nil)
let fileHandle = FileHandle(forWritingAtPath: stdout)!
// Complete the Challenge
func challenge(arr: [[Int]]) -> Int {
// nothing printed to the console
print("Hello")
// will print to the console using "fileHandle"
fileHandle.write("HackerRank Challenge\n".data(using: .utf8)!)
return 0
}
HackerRank - Print the Elements of a Linked List
// Complete the printLinkedList function below.
/*
* For your reference:
*
* SinglyLinkedListNode {
* int data;
* SinglyLinkedListNode next;
* }
*
*/
function printLinkedList(head) {
while(head != null) {
console.log(head.data);
head = head.next;
}
}
After running the code Congratulations!
// Complete the printLinkedList function below.
/*
* For your reference:
*
* SinglyLinkedListNode {
* data: Int
* next: SinglyLinkedListNode?
* }
*
*/
func printLinkedList(head: SinglyLinkedListNode?) -> Void {
var head = head
while let currentNode = head {
print(currentNode.data)
head = currentNode.next
}
}
After running the code Compiler error :(
- JavaScript has autocomplete support, Swift does not.
- JavaScript runs tests much faster.
- Swift encounters way more edge case run issues within the HackerRank compiler.