-
-
Save jt3k/4355965 to your computer and use it in GitHub Desktop.
Задачка из вакансий яндыкса
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
/* | |
Задача: | |
function reversePrint(linkedList) { | |
// ... | |
} | |
var someList = { | |
value: 1, | |
next: { | |
value: 2, | |
next: { | |
value: 3, | |
next: { | |
value: 4, | |
next: null | |
} | |
} | |
} | |
}; | |
reversePrint(someList); | |
Напишите код функции (reversePrint), которая выведет значения | |
переданного ей односвязного списка в обратном порядке (4,3,2,1). | |
Для вывода значений используйте конструкцию console.log. | |
*/ | |
var reversePrint = function(linkedList) { | |
if(linkedList.next){ | |
reversePrint(linkedList.next); | |
} | |
console.log(linkedList.value); | |
}; | |
var someList = { | |
value: 1, | |
next: { | |
value: 2, | |
next: { | |
value: 3, | |
next: { | |
value: 4, | |
next: null | |
} | |
} | |
} | |
}; | |
reversePrint(someList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment