Index: src/wp-includes/class.wp-dependencies.php
===================================================================
--- src/wp-includes/class.wp-dependencies.php	(revision 36589)
+++ src/wp-includes/class.wp-dependencies.php	(working copy)
@@ -385,7 +385,7 @@
 		$group = (int) $group;
 
 		if ( $recursion )
-			$group = min($this->group, $group);
+			$this->group = $group = min($this->group, $group);
 		else
 			$this->group = $group;
 
Index: tests/phpunit/tests/dependencies/scripts.php
===================================================================
--- tests/phpunit/tests/dependencies/scripts.php	(revision 36589)
+++ tests/phpunit/tests/dependencies/scripts.php	(working copy)
@@ -199,4 +199,25 @@
 		$this->assertContains( home_url( 'bar.js' ), $footer );
 		$this->assertContains( home_url( 'baz.js' ), $footer );
 	}
+
+	/**
+	 * @ticket 35873
+	 */
+	function test_wp_register_script_with_dependencies_in_head_and_footer() {
+		wp_register_script( 'parent', home_url( 'parent.js' ), array( 'child' ), '1', true ); // in footer
+		wp_register_script( 'child', home_url( 'child.js' ), array( 'grandchild' ), '1', false ); // in head
+		wp_register_script( 'grandchild', home_url( 'grandchild.js' ), array(), '1', true ); // in footer
+
+		wp_enqueue_script( 'parent' );
+
+		$header = get_echo( 'wp_print_head_scripts' );
+		$footer = get_echo( 'wp_print_footer_scripts' );
+
+		$expected_header  = "<script type='text/javascript' src='http://example.org/grandchild.js?ver=1'></script>\n";
+		$expected_header .= "<script type='text/javascript' src='http://example.org/child.js?ver=1'></script>\n";
+		$expected_footer  = "<script type='text/javascript' src='http://example.org/parent.js?ver=1'></script>\n";
+
+		$this->assertEquals( $expected_header, $header );
+		$this->assertEquals( $expected_footer, $footer );
+	}
 }
