Last active
March 13, 2023 11:47
-
-
Save periakteon/1a13f67f767bc71ba57d594bf05f9e59 to your computer and use it in GitHub Desktop.
stand-in-line-solution.js
This file contains hidden or 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 nextInLine(arr, item) { | |
//Argüman olarak verilecek olan "item"ı, yani sayıyı array'in sonuna ekliyoruz | |
arr.push(item); | |
//array'in ilk elemanını siliyoruz ve silinen elemanı döndürüyoruz | |
return arr.shift(); | |
} | |
//testArr adında bir dizi oluşturuyoruz | |
const testArr = [1,2,3,4,5]; | |
console.log("Before: " + JSON.stringify(testArr)); | |
// Before: [1,2,3,4,5] | |
console.log(nextInLine(testArr, 6)); | |
// 1 (Hatırlayın: İlk elemanı sil ve silinen elemanı döndür demiştik) | |
console.log("After: " + JSON.stringify(testArr)); | |
// After: [2,3,4,5,6] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment